Amazon Interview Question
SDE1sCountry: Luxembourg
Interview Type: Phone Interview
You can do this in O(nlgn) by sorting the array and searching
To do it in O(n) I think you need O(n) extra space. You can use a hash map and then hash the numbers as you see. If the number is not present in the HashMap, you add it. If it is already present you remove it. In the end the only number remaining in the hash map will be the number you need.
Take XOR of all the numbers of array. Resulting number in XOR is the answer.
- Nitin Gupta February 20, 2014