Easy Bit Manipulation

Single Number

Receives an array of integers in which every value appears exactly twice except one, and returns that single unpaired value. It solves this with a single O(n) pass that XORs every element together: XOR is commutative and associative, and a value XORed with itself cancels to 0, so every duplicate pair cancels out and only the unpaired value survives in the running result. Returns that integer using no extra data structure — O(n) time, O(1) extra space.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References