Maximum XOR of two numbers in an array
Medium Accuracy: 81.56% Submissions: 3193 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:

​Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
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)
 
Constraints:
1 <= N <=2*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.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Maximum XOR of two numbers in an array

Output Window