#2996
Smallest Missing Integer Greater Than Sequential Prefix Sum
pupil · 555 · lc easy +28 · verified · 35.2% accepted · 175 likes · top 13%
Description
You are given a 0-indexed integer array nums.
A prefix nums[0..i] is sequential if nums[j] = nums[j - 1] + 1 for all 1 <= j <= i. The single-element prefix nums[0..0] is always sequential.
Return the smallest integer x that is absent from nums and is greater than or equal to the sum of the longest sequential prefix.
Example 1:
Input: nums = [1,2,3,2,5]
Output: 6
Explanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
Example 2:
Input: nums = [3,4,5,1,12,14,13]
Output: 15
Explanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
Code
1
2
3