Maximum XOR of Two Numbers in an Array
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an array of non-negative integers nums, return the maximum value of nums[i] XOR nums[j] over all index pairs with 0 <= i <= j < nums.length.
Because i may equal j, a single-element array returns 0.
Aim for O(n * B) time where B is the number of bits (31 here), using a binary trie or a greedy bit-by-bit prefix search.
Examples
Constraints
- 1 <= nums.length <= 2 * 10^5
- 0 <= nums[i] <= 2^31 - 1
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.