Approach hintTry it first, then revealHide
Insert the numbers into a binary trie from bit 30 down. For each number, walk the trie preferring the opposite bit at every level, because one higher bit outweighs all the lower bits together. O(n log C).
Insert the numbers into a binary trie from bit 30 down. For each number, walk the trie preferring the opposite bit at every level, because one higher bit outweighs all the lower bits together. O(n log C).