Missing Number
Real-world version: Unclaimed Badge NumberThe statement here is our own: the same inputs, outputs and technique.
A site office owns one visitor badge for each whole number from 0 up to and including n. At closing time a clerk empties the drop tray and writes down what she finds there.
You get her note as the array returned. Its length is n, no number shows up twice, and each number she wrote sits somewhere in 0 through n inclusive, so exactly one badge of the set failed to come back.
Report the number printed on the badge that is still out.
Examples
Example 1
- Input
- returned = [2, 5, 0, 1, 4]
- Output
- 3
Five badges came back, so the office owns badges 0 through 5. Only 3 is absent from the tray.
Example 2
- Input
- returned = [0]
- Output
- 1
One badge came back out of the pair numbered 0 and 1, and the one still out is the higher of the two.
Example 3
- Input
- returned = [5, 3, 1, 0, 2, 6]
- Output
- 4
The tray covers 0 through 6 apart from 4, which never made it back.
Constraints
- n == returned.length
- 1 <= n <= 10^4
- 0 <= returned[i] <= n
- No value repeats inside returned
- Exactly one value of 0..n is absent from returned
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 unclaimed_badge(returned: list[int]) -> int:public int unclaimedBadge(int[] returned)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 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