Insert numbers MSB-first into a 0/1 trie, then watch a query walk down choosing the opposite bit to maximize XOR. Switch modes to build the linear basis by reducing each value.
junior.md and professional.md for the proof that the greedy opposite-bit walk is optimal (most-significant differing bit dominates).