An array ‘A’ of ‘N’ integers is provided. Return the maximum possible number which can be created by taking bitwise XOR of any 2 integers of the array.
If the array is 2,5 and 6
2 XOR 5 is 7
2 XOR 6 is 4
5 XOR 6 is 3
Hence the answer is 7.
The first line contains one integer ‘N’, denoting the size of the array.
The next line contains 'N' space-separated integers representing the elements of 'A'.
Output Format:
Print a single integer in a new line denoting the maximum xor value.
Note:
You are not required to print the expected output. It has already been taken care of. Just implement the function.
3
2 1 4
6
Select the 1st and 3rd element leading to a xor value of 6.
2
3 2
1
1 <= N <= 10^4
1 <= A[i] <= 10^9
Time Limit: 1 sec
Can we check all possible combinations of taking two indexes?
To find the maximum possible among all such pairs, we can use two nested loops to check all possible pairs and store the maximum possible xor value.
Algorithm:
O(N ^ 2), where ‘N’ is the size of the array.
Since we are using two nested loops to find all possible pairs, so the total time complexity is O(N ^ 2).
O(1)
We are using constant extra space.