Maximum XOR with trie

Write codeHard35 minGoogle style

Your task

Given an array of non-negative integers, find the maximum value of arr[i] XOR arr[j] over all pairs i != j. Insert each number's binary representation into a binary trie (most-significant bit first); for each number, greedily walk the trie preferring the opposite bit at each level to maximize the running XOR. Return the maximum XOR found. The array can have up to 2e5 elements with values up to 2^31, so an O(n * bits) trie solution is expected (O(n^2) will time out).

Examples

max_xor_pair(nums: list[int]) -> int
Example 1
Inputmax_xor_pair([3, 10, 5, 25, 2, 8])
Output28