Skip to main content

Maximum XOR of Two Numbers in an Array

MediumArrayBit Manipulation

Description

Given an integer array nums, return the maximum XOR of two numbers in the array. Use a trie for O(n) solution.

Examples

Input:nums = [3,10,5,25,2,8]
Output:28
Explanation:

Maximum XOR is 5 ^ 25 = 28.

Input:nums = [1]
Output:1
Explanation:

Edge case with a single-element array.

Input:nums = [14, 70, 53, 83, 49, 91, 36, 80, 92, 51, 66, 70]
Output:127
Explanation:

The maximum XOR is 127, achieved by 36 ^ 91.

Constraints

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

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.