EY Interview Question

An array of 99 elements contains integers from 1 to 100 with one missing element. Find the missing element?

Interview Answer

Anonymous

Dec 6, 2019

iterate over array to get sum and subtract it from sum of 100 natural numbers from formula - n*(n-1)/2. Another method is to XOR elements of array and XOR of 100 natural numbers and then XOR both of them. Result is missing number. Both methods have complexity O(n).