Bit manipulationAnimated
Find Single Non-Repeating Element
XOR every number; pairs cancel and the single one remains.
Time
O(n)
Extra space
O(1)
Use it for
One unique value among pairs.
How it works
- Every number appears twice except one.
- XOR all the numbers together.
- Equal numbers cancel (x ^ x = 0) and 0 changes nothing, so only the single number survives.
- One pass, O(1) extra memory.
Watch it run
Loading animation…