Overview - Two Non Repeating Elements in Array Using XOR
What is it?
Given an array where every element appears exactly twice except for two elements which appear once, find those two unique elements. The XOR-based solution achieves O(n) time and O(1) space by exploiting XOR properties: a ^ a = 0, a ^ 0 = a, and the fact that XOR of all elements gives xor of the two unique elements.
Why it matters
This problem demonstrates advanced bit manipulation — specifically using a single differing bit to partition elements into two groups. It is a direct extension of the 'one non-repeating element' problem and appears frequently in bit manipulation interview rounds. In Rust, the ^ operator works identically to other languages but Rust's type system ensures no integer overflow surprises.
Where it fits
You need to understand XOR properties (a^a=0, a^0=a) and the 'find one non-repeating element' solution before tackling this. After mastering it, finding the missing number, detecting single corrupt elements, and Gray code generation follow naturally.
