Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
@ NotThatBad: ≈≈≈Ω©√ç∂∂©ƒ∂©ƒ∂©ƒ∂√熃©ƒ©ƒ†ƒ''
Yeah! Just splitting code without explaining what the heck ran in your mind and how you came to this solution makes your interviewer or any reader who drops in here fell like above. Next time, remember, people dont care to just read some random code but to read some explanation!
@AmzFAILFacebookFailMSFTFail: please accept my apologies for not providing the explanation.
xor'ing a number with itself even number of times will results in a 0 and xor'ing the number with itself odd number of times will results in the number itself. I have used this nature of xor operation to reach to this result.
Again, how about a hashmap.
Add each of the elements to the hashmap on its first occurrence and remove it from the hashmap on its second occurrence. This way at the end only the object of our interest remains in the hashmap and can be found easily.
Time Complexity:O(n)
Space Complexity:O(n)
- NotThatBad January 17, 2012