Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.
Input: nums = [3,10,5,25,2,8]
Output: 28
Explanation: The maximum result is 5 XOR 25 = 28.
Input: nums = [14,70,53,83,49,91,36,80,92,51,66,70]
Output: 127
For the brute force method, we consider each possible pair of numbers in the array and calculate their XOR. The XOR operation will give us a number with bits set where the bits differ between the two numbers. Our task is to find the two numbers that maximize this XOR. This approach checks all pairs and picks the one with the maximum XOR value.
maxXOR to zero.(A[i], A[j]) in the array, compute the XOR A[i] ^ A[j].maxXOR if the computed XOR is greater than maxXOR.maxXOR.The key idea is to use a Trie (prefix tree) to efficiently find two numbers in the array that can form the maximum XOR result. By inserting all numbers in the Trie and using bit manipulation, we can find pairs leading to maximum XOR efficiently. This relies on the fact that XOR tends to maximize when we have opposing bits (i.e., one bit is 0, the other is 1).
0 or 1.