Code Room
CodingHardcod-g539
Subject TrieLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.