Smallest Missing Integer Greater Than Sequential Prefix Sum
Real-world version: First Free Locker CodeThe statement here is our own: the same inputs, outputs and technique.
A gym's handover log lists the locker codes handed out today, in the order they were handed out, as nums.
Look at the front of the log. A run of codes starting at the very first entry is called a ladder when every code in it is exactly one above the code before it; the first entry on its own always counts as a ladder. Let total be the sum of the codes in the longest ladder the log begins with.
Return the smallest integer that is at least total and does not appear anywhere in nums.
Examples
Example 1
- Input
- nums = [4,5,6,2,9]
- Output
- 15
The log begins with the ladder 4, 5, 6, because 2 does not follow 6. Its codes add up to 15, and 15 never appears in the log.
Example 2
- Input
- nums = [7,8,3,15,16,17]
- Output
- 18
The longest ladder at the front is 7, 8, which totals 15. The log already shows 15, 16 and 17, so the first value at or above 15 that is free is 18.
Example 3
- Input
- nums = [9,20]
- Output
- 10
20 does not follow 9, so the ladder holds only the code 9 and the total is 9. The log shows 9 itself, and 10 is free.
Constraints
- 1 <= nums.length <= 50
- 1 <= nums[i] <= 50
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def missing_integer(nums: list[int]) -> int:public int missingInteger(int[] nums)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's