AlgoScope

XOR Pairing (Single Number)

XOR everything. Duplicates cancel and the unpaired value remains.

Bit manipulation, algorithm, intermediate
XOR 4 into the accumulator, giving 4.4011221324i
XOR 4 into the accumulator, giving 4.4011221324i

XOR Tricks: Find the single number

Decision, step 2 of 7

0 xor 4 = 4. First time 4 appears, so its bits are folded in.

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Taught by the same lesson

XOR Tricks covers these too, in the same run.