Problems > Maximum XOR of a Pair

Maximum XOR of a Pair

Difficulty: 1800 3500 ms 128 MB

bitwise

Choose two elements (possibly equal indices forbidden, N ≥ 2) maximizing ai ⊕ aj. Print the maximum XOR.

Input: the first line has N; the second line has N non-negative integers.

Output: the maximum pairwise XOR.

Constraints:

  • 2 ≤ N ≤ 105
  • 0 ≤ ai < 230

Sample Tests

Input 1
3
2 4 5
Output 1
7
Input 2
2
8 8
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.