Maximum XOR of Two Numbers in an Array
Medium
LC #421
triebit manipulationgreedyNot attempted yet
Return the largest value of nums[i] ^ nums[j] over all
0 ≤ i ≤ j < n (a number paired with itself gives 0).
Checking every pair is O(n²). Can you do better?
Example 1
Input: nums = [3, 10, 5, 25, 2, 8]
Output: 28
5 ^ 25 = 00101 ^ 11001 = 11100 = 28
Example 2
Input: nums = [8, 1, 2]
Output: 10
8 ^ 2 = 1000 ^ 0010 = 1010
Example 3
Input: nums = [7]
Output: 0
Constraints
- 1 ≤ len(nums) ≤ 2 · 10⁴
- 0 ≤ nums[i] ≤ 2³¹ - 1