Maximum XOR of Two Numbers in an Array
Signals to notice
Brute force first
XOR every pair. Checks all pairs without exploiting bit structure. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
The key insight
Build a binary trie (each path is a number's bit representation from MSB to LSB). For each number, greedily traverse the trie choosing the opposite bit at each level to maximize XOR. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
What must stay true
To maximize XOR, you want opposite bits at every position (1 XOR 0 = 1). The trie lets you greedily choose the opposite bit at each level — if it exists, take it; otherwise, take what's available. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Easy way to go wrong
Building a decimal trie instead of a binary trie — each node has exactly 2 children (0 and 1), representing each bit position from most significant to least. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.