Maximum XOR of Two Numbers in an Array

Given an integer array nums, return the maximum XOR value of any pair of numbers. Pattern focus: Check kth Bit. Build the best XOR greedily from the most significant bit down to the least significant bit.

Input Format

nums = array of integers

Output Format

maximum XOR value among all pairs

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • nums must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

nums = [3,10,5,25,2,8]

Output:

28

Explanation:

25 XOR 5 = 28 is the best pair.

Example 2:

Input:

nums = [0,2]

Output:

2

Explanation:

0 XOR 2 = 2.

Loading...
Maximum XOR of Two Numbers in an Array