A booth issues numbered ticket stubs 0, 1, 2, \dots, n (that is, n + 1 stubs in total). At closing time the clerk's log should contain all n + 1 stub numbers, but exactly one entry was never logged, so the log holds only n of the n + 1 values (all distinct, each in the range [0, n]).
Given the log, determine which single stub number is missing.
Line 1: an integer n.
Line 2: n space-separated distinct integers, each in [0, n] (this line is empty when n = 0).
A single integer: the one value in [0, n] that does not appear in the log.
Example 1
Input
3 0 1 3
Expected
2
Explanation
Stub numbers should be 0,1,2,3; the log shows 0,1,3 so ticket 2 is missing.
Example 2
Input
1 0
Expected
1
Explanation
Stubs should be 0 and 1; only 0 appears in the log, so 1 is missing.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →