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.

30:00

Maximum XOR of Two Numbers in an Array
medium
Topics
Companies

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
Constraints:
  • 1nums.length2×1051 \leq \text{nums.length} \leq 2 \times 10^5

  • 0nums[i]23110 \leq \text{nums}[i] \leq 2^{31} - 1

Input
arr =[3,10,5,25,2,8]

Starting with 6 numbers. Will check bit by bit from MSB.

Numbers (Binary)
3
0
0
0
0
0
0
1
1
10
0
0
0
0
1
0
1
0
5
0
0
0
0
0
1
0
1
25
0
0
0
1
1
0
0
1
2
0
0
0
0
0
0
1
0
8
0
0
0
0
1
0
0
0
Bit-by-Bit Processing
Current Bit
-
Prefix Mask

00000000

Prefixes in Set (0)
Maximum XOR

0

(00000000)

Variables
No variables to display
DepthFunction Call
Stack empty
0/6