Menu Close

Find the maximum result of = a XOR b

Given a non-empty array of numbers, a0, a1, a2 ….. where 0 ≤ ai < 2^31. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?

Input: [3, 10, 5, 25, 2, 8]

Output: 28
def MaXor(arry,N):
    L=[]
    temp=0
    for i in range(N):
        L.clear()
        L.append(temp)
        temp=0
        for j in range(N):
            if i!=j:
                L.append(arry[i] ^ arry[j])
            temp=max(L)
    return temp

Array=list(map(int,input('Enter the list of numbers : ').split(' '))) 
#or 
#Array=[3,10,5,25,2,8]
print(MaXor(Array,len(Array)))

Input_1:
Enter the list of numbers : 3 10 5 25 2 8

Output:
28


Input_2:
Enter the list of numbers : 0

Output:
0


Input_3:
Enter the list of numbers : 2 4

Output:
6


Input_4:
Enter the list of numbers : 8 10 2

Output:
10


Input_5:
Enter the list of numbers : 14 70 53 83 49 91 36 80 92 51 66 70
Output:
127


Illustration of the Output:

Executed using python3 Linux Terminal

More Q