You're given a 0-indexed array of integers nums. Your task is to find the smallest missing integer that meets a specific condition.
What makes a prefix "sequential"?
A prefix nums[0..i] is sequential if each element (starting from index 1) is exactly one more than the previous element. In other words, nums[j] = nums[j-1] + 1 for all 1 ≤ j ≤ i.
Your Mission:
Find the longest sequential prefix, calculate its sum, then return the smallest integer missing from the array that is greater than or equal to this sum.
Example walkthrough:
For [4, 5, 6, 7, 6, 1, 1]:
• Longest sequential prefix: [4, 5, 6, 7] (length 4)
• Sum: 4 + 5 + 6 + 7 = 22
• Missing integers ≥ 22: We need to check 22, 23, 24... until we find one not in the array
• Answer: The first missing integer ≥ 22
Input & Output
Constraints
- 1 ≤ nums.length ≤ 50
- 1 ≤ nums[i] ≤ 50
- The array is 0-indexed
- A prefix consisting only of nums[0] is always considered sequential