Find the maximum value of over pairs of elements where the chosen pair must satisfy the constraints of the original problem’s ordering rule.
You are given an array of integers. Consider all valid pairs of positions that can be formed according to the problem’s ordering constraint, and compute the bitwise XOR of the two values in each valid pair.
Your task is to determine the maximum XOR value among all valid pairs.
The key challenge is that checking every pair directly is too slow for large arrays, so the solution must exploit structure in the way valid pairs are formed.
Input Format
Input
- The first line contains an integer — the number of array elements.
- The second line contains integers .
Interpretation
- All values are treated as integers suitable for bitwise XOR.
Output Format
Output
- Print a single integer: the maximum XOR value among all valid pairs.
Constraints
- The array size is large enough that an approach is not intended.
- Values fit in standard 32-bit signed integer ranges unless otherwise stated by the platform.
Example 1
Input
3 1 2 3
Output
1
Explanation
Among the valid candidate pairs considered by the ordering rule, the best XOR value is .
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.