Skip to interview prep
Apexed

Every element appears an even number of times except one that appears an odd number of times. Find it.

EasySearching & selection

Technical

Content review

Report an error

Not yet reviewed

Type or dictate your answer. Your draft is saved on this device.

Show model answer

XOR all elements. XOR is associative and commutative, and x ⊕ x = 0, so every pair cancels and the odd-occurrence element remains. O(n) time and O(1) space, versus O(n) space for a hash map of counts.

Every element appears an even number of times except one that appears an odd number of times. Find it. — Data structures & algorithms interview question — Apexe