Proficient Level
Implement the maximumXorPairSimple method that returns the maximum XOR value obtainable from any pair.
The input array nums contains size integers.
Your task is to choose two numbers from the array such that their XOR value is as large as possible, and return that maximum XOR value.
For example, in [3,10,5,25,2,8], the pair 5 and 25 gives XOR value 28, which is the maximum.
A simple way is to check every possible pair.
Start with the maximum XOR as 0. For every index i, compare it with every index after it. Calculate nums[i] XOR nums[j] and update the answer when this value is larger.
This brute-force method is easy to understand and works correctly for small inputs.
Pseudocode:
function maximumXorPairSimple(nums, size):
maxXor = 0
for i from 0 to size - 1:
for j from i + 1 to size - 1:
current = nums[i] XOR nums[j]
if current > maxXor:
maxXor = current
return maxXor