Maximum XOR of two numbers
XOR gives a 1 wherever two numbers differ, and a 1 in a higher bit beats everything the lower bits can add. So store the numbers in a trie of bits, highest bit first, and for each number walk down taking the opposite bit whenever that child exists.
num and xor show the bits, numbered as in the code (i, highest first). The number under a leaf is the number stored on that path.