Practice finding the maximum bitwise XOR of an allowed array pair, including equal indices. Handle duplicates, singleton arrays, and the full nonnegative 31-bit range.
# Find the Largest XOR Value From an Array Pair
Given a nonnegative integer array `nums`, return the maximum value of `nums[i] XOR nums[j]` over indices satisfying `0 <= i <= j < nums.length`.
`XOR` is the bitwise exclusive-or operation.
### Function
`int findMaximumXOR(vector<int>& nums)`
### Example 1
```text
Input: nums = [1,2,4]
Output: 6
```
The largest value comes from `2 XOR 4`, whose binary form is `110`.
### Example 2
```text
Input: nums = [2147483647]
Output: 0
```
The same index may be used for both operands, and a value XOR itself is zero.
### Constraints
- `1 <= nums.length <= 200000`.
- `0 <= nums[i] <= 2147483647`.
### Clarifications
Return the maximum XOR value, not the two indices or their sum. Repeated values are allowed. Choosing the same index is permitted by the stated index range.
### What a Strong Answer Covers
- Bitwise XOR and the importance of higher result bits.
- Duplicate values, a single value, and the full nonnegative 31-bit range.
- Why the maximum is achieved by some allowed pair.
- Time, storage, and arithmetic bounds at the maximum array size.
Overview: Practice finding the maximum bitwise XOR of an allowed array pair, including equal indices. Handle duplicates, singleton arrays, and the full nonnegative 31-bit range.
Given a nonnegative integer array nums, return the maximum value of nums[i] XOR nums[j] over indices satisfying 0 <= i <= j < nums.length.
XOR is the bitwise exclusive-or operation.
Function
int findMaximumXOR(vector<int>& nums)
Example 1
Input: nums = [1,2,4]
Output: 6
The largest value comes from 2 XOR 4, whose binary form is 110.
Example 2
Input: nums = [2147483647]
Output: 0
The same index may be used for both operands, and a value XOR itself is zero.
Constraints
1 <= nums.length <= 200000
.
0 <= nums[i] <= 2147483647
.
Clarifications
Return the maximum XOR value, not the two indices or their sum. Repeated values are allowed. Choosing the same index is permitted by the stated index range.
What a Strong Answer Covers Guidance
Bitwise XOR and the importance of higher result bits.
Duplicate values, a single value, and the full nonnegative 31-bit range.
Why the maximum is achieved by some allowed pair.
Time, storage, and arithmetic bounds at the maximum array size.