 All Problems
Maximum XOR of Two Numbers in an Array
medium
trie
bit manipulation
hash table
amazon
google
facebook

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

Example 1:

Input:  3 10 5 25 2 8
Output: 28

(5 XOR 25 = 28)

Example 2:

Input:  0
Output: 0

Constraints:

  • 1 ≤ nums.length ≤ 2 × 10⁵
  • 0 ≤ nums[i] ≤ 2³¹ - 1

Input format: Space-separated integers.

Output format: Maximum XOR value.

Run to check your code against the sample cases, or submit to run every case