XOR Pairing (Single Number)
XOR everything; duplicates cancel and the unpaired value remains.
Decision · step 2 of 7XOR Tricks: Find the single number
0 xor 4 = 4. First time 4 appears, so its bits are folded in.
What you will see
A running XOR row; each duplicate pair zeroes itself out.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, run it on your own input, try operations in any order.
Screen readers: Each bit announces its position and value; each step announces the operation and the resulting number in binary and decimal.
Reduced motion: Bits flip with a crossfade; masks appear in place.