A roster assigns badge ids 0, 1, 2, ..., n (that is n + 1 distinct ids). A scanner then reads n of them exactly once each, so exactly one id from the full set is missing. Given the n scanned ids in some arbitrary order, determine the single missing id.
Line 1: an integer n.
Line 2: n space-separated distinct integers, each in the range 0..n, the scanned ids.
A single integer: the one id in 0..n that was not scanned.
n distinct values, each between 0 and n inclusive.Example 1
Input
3 0 1 3
Expected
2
Explanation
The full set is {0,1,2,3}; 2 is the only id not scanned.
Example 2
Input
1 1
Expected
0
Explanation
The full set is {0,1}; only 1 was scanned, so 0 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 →