Smallest Missing Integer Greater Than Sequential Prefix Sum - Problem
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.
Input & Output
Example 1 — Sequential Start
$
Input:
nums = [1,2,3,5,6]
›
Output:
7
💡 Note:
Sequential prefix is [1,2,3] with sum 6. Numbers 6 exists in array, but 7 is missing, so return 7.
Example 2 — Single Element Prefix
$
Input:
nums = [1,3,6,4,1,6]
›
Output:
3
💡 Note:
Sequential prefix is [1] with sum 1. Check: 1 exists, 2 is missing, so return 2. Wait - let me recalculate: 2 is missing, so return 2.
Example 3 — Longer Sequence
$
Input:
nums = [3,4,5,1,12,14,13]
›
Output:
15
💡 Note:
Sequential prefix is [3,4,5] with sum 12. Numbers 12, 13, 14 all exist, but 15 is missing, so return 15.
Constraints
- 1 ≤ nums.length ≤ 50
- 1 ≤ nums[i] ≤ 50
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with potential sequential start
2
Find Sequential Prefix
Identify consecutive sequence from beginning
3
Calculate Sum & Find Missing
Sum prefix then find first missing number >= sum
Key Takeaway
🎯 Key Insight: Find the longest sequential prefix from the start, then search for the first missing number >= prefix sum
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code