Max XOR Pair Problem
Max XOR Pair Problem — ExecCode Hard DSA Practice
Solve the Max XOR Pair problem on ExecCode. Free online hard DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Pick two (not necessarily distinct index) numbers to maximize their bitwise XOR. Checking all pairs is too slow. Return the maximum XOR of any two elements (you may pick the same element twice only if it appears twice; typically pick two indices i, j, i and j may be equal only if you want nums[i]^nums[i]=0 which is never best unless n=1). You are given: nums — non-negative integers Return integer XOR. Order of the pair does not matter.
Examples
Input {'nums': [3, 10, 5, 25, 2, 8]}; Output 28. Input {'nums': [0, 0]}; Output 0. Input {'nums': [8, 1]}; Output 9
Constraints
n >= 1; if n==1 the only XOR is 0 Values fit in 32 bits
Practice Max XOR Pair free on ExecCode. Browse DSA problems, topic map, and placement guides.