Problem Statement
Given n numbers in range [0,n] with one missing, how do you find the missing number in O(n) time and O(1) space?
Explanation
XORing all numbers from 0 to n and XORing all present numbers yields the missing number since x^x=0 and x^0=x. This gives O(n) time and O(1) space without overflow risk of sum.
Code Solution
SolutionRead Only
int res=0; for(int i=0;i<=n;i++) res ^= i; for(int num:nums) res ^= num; return res;
