You know XOR cancellation — x ^ x = 0. That handles "find the unique element," but what happens when you need to find the maximum XOR between any two numbers in an array? Or answer a stream of queries like "what's the max XOR of x with any number ≤ m"?
The naive approach — check every pair — is O(N²). For N = 10⁵, that's 10 billion operations. We can do much better.
Enter the Binary Trie. A trie over the binary representation of numbers. Each level branches on one bit. Insert all numbers, then for each number, traverse the trie greedily choosing the opposite bit at each step. This gives you the partner that maximizes XOR.
The core insight in one sentence: