Maximum XOR of Two Numbers in an Array

Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

Example 1
Inputnums = [3,10,5,25,2,8]
Output28
The maximum result is 5 XOR 25 = 28.
Example 2
Inputnums = [14,70,53,83,49,91,36,80,92,51,66,70]
Output127
The maximum XOR result among pairs in the array is 127.

Constraints

  • 1 <= nums.length <= 2 * 10^5
  • 0 <= nums[i] <= 2^31 - 1

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate