Find the Missing Number Using XOR
Easyjavapythonccppjavascript
An array contains N distinct values chosen from 0 to N (so exactly one value in that range is missing). Find the missing value using XOR.
Input Format
The first line contains an integer N (the array length). The second line contains N space-separated distinct integers, each between 0 and N.
Output Format
Print the missing number.
Example 1
Input
3 3 0 1
Output
2
Explanation: The full range is 0,1,2,3; only 2 is missing.
- 1 <= N <= 1000000
- The array holds N of the N+1 numbers 0..N.