Code RoomMaximum XOR with trie
HardPrep Room Coding #1106

Maximum XOR with trie

CodingAlgorithms & data structuresSenior–Staff~35 min

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).

Implement
max_xor_pair(nums: list[int]) → int
Examples
in[[3,10,5,25,2,8]]out28
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[3,10,5,25,2,8]]28not run yetsample