A ground station tracks a fleet of n drones, each broadcasting a non-negative integer identification code. To gauge signal diversity, the station wants the largest possible XOR value obtainable by pairing any two different drones (by index; the two drones' codes may still be numerically equal).
Given the codes, find the maximum XOR of any such pair.
Line 1: an integer n.
Line 2: n space-separated non-negative integers, the drone codes.
A single integer: the maximum XOR value over all pairs of distinct indices i \ne j.
Example 1
Input
3 9 5 12
Expected
12
Explanation
9 XOR 5 = 12, which is larger than 9 XOR 12 (5) and 5 XOR 12 (9), so the answer is 12.
Example 2
Input
2 1 2
Expected
3
Explanation
The only pair is (1,2); 1 XOR 2 = 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →