Maximum XOR Pair
Given an array of integers, find the maximum XOR value between any two elements in the array.
Function Signature:
from typing import List
def max_xor_pair(nums: List[int]) -> int:
"""
Finds the maximum XOR value between any two elements in the array.
Parameters:
- nums: A list of integers.
Returns:
- int: The maximum XOR value.
"""
# Your code here
Example:
# Example 1:
nums = [3, 10, 5, 25, 2, 8]
result = max_xor_pair(nums)
print(result) # Output should be 28
# Explanation: The maximum XOR value between any two elements in the array is obtained by XORing 5 and 25 (5 ^ 25 = 28).
# Example 2:
nums = [0, 1, 2, 3, 4, 5]
result = max_xor_pair(nums)
print(result) # Output should be 7
# Explanation: The maximum XOR value between any two elements in the array is obtained by XORing 3 and 4 (3 ^ 4 = 7).
Note:
- The XOR operation (symbolized by
^
in python) computes the bitwise XOR (exclusive OR) of two integers. - The maximum XOR value is obtained by finding the bitwise XOR of two elements such that the result is maximum.
Instructions:
- Implement the
max_xor_pair
function to solve the problem. - Use Python for your implementation.
- Provide clear comments in your code to explain the logic.
- Discuss the time and space complexity of your solution.
As always, we’ll share our solution to this problem tomorrow. Stay tuned 😊