Problem
Given a non-empty array where every element appears twice except for one, find that single element. Must run in O(n) time and O(1) space.
References
Difficulty
🟢 Easy
Companies
Amazon, Google, Microsoft
Notes
Language: Java
XOR all elements. Pairs cancel out (a ^ a = 0). Result is the single element.
Problem
Given a non-empty array where every element appears twice except for one, find that single element. Must run in O(n) time and O(1) space.
References
Difficulty
🟢 Easy
Companies
Amazon, Google, Microsoft
Notes
Language: Java
XOR all elements. Pairs cancel out (a ^ a = 0). Result is the single element.