207. Maximum XOR of two numbers in an array

Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

Example 1:

Input : nums = [3, 9, 10, 5, 1]

Output : 15

Explanation :

The maximum XOR value is 10 XOR 5 => 15.

Example 2:

Input : nums = [26, 49, 30, 15, 69]

Output : 116

Explanation :

The maximum XOR value is 69 XOR 49 => 116.

Now Your Turn!

Pick the correct output for the given input

Input : nums = [1, 2, 3, 4, 5, 6]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 105
  • 0 <= nums[i] <= 231 - 1

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int findMaximumXOR(vector<int>& nums) {
//your code goes here
}
};
Test Case

Input:

Nums