Smallest Missing Integer Greater Than Sequential Prefix Sum

You are given a 0-indexed array of integers nums.

A prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.

Return the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.

Example 1
Inputnums = [1,2,3,2,5]
Output6
The longest sequential prefix of nums is [1, 2, 3] with a sum of 6; 6 is not in the array, so it is the smallest missing integer greater than or equal to that sum.
Example 2
Inputnums = [3,4,5,1,12,14,13]
Output15
The longest sequential prefix of nums is [3, 4, 5] with a sum of 12; 12, 13, and 14 are in the array while 15 is not.

Constraints

  • 1 <= nums.length <= 50
  • 1 <= nums[i] <= 50

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate