Copied to Clipboard
Maximum XOR of two numbers in an array
Medium Accuracy: 79.25% Submissions: 3995 Points: 4

Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.

Example 1:

Arr = {25, 10, 2, 8, 5, 3}
Output: 28
The maximum result is 5 ^ 25 = 28.

Example 2:

Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result is 1 ^ 6 = 7.
Your task :
You don't need to read input or print anything. Your task is to complete the function max_xor() which takes an array of integers and it's size as input and returns maximum XOR of two numbers in an array.
Expected Time Complexity: O(NlogN)
Expected Auxiliary Space: O(N)
1 <= N <=5*104
1<= A[i] <= 106

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Maximum XOR of two numbers in an array

Output Window