Problem · Array
Maximum XOR Between Two Arrays
Learn this problemProblem statement
You are given two non-empty arrays of non-negative integers, arr1 and arr2.
Choose one value A from arr1 and one value B from arr2. Return the maximum possible value of A xor B over all such cross-array pairs.
Function
maximumXorBetweenArrays(arr1: int[], arr2: int[]) → intExamples
Example 1
arr1 = [6,6,0,6,8,5,6]arr2 = [1,7,1,7,8,0,2]return = 15Choosing 8 from arr1 and 7 from arr2 gives 8 xor 7 = 15.
Example 2
arr1 = [25,10,2]arr2 = [8,5,3]return = 28Choosing 25 and 5 gives 25 xor 5 = 28, the largest cross-array value.
Constraints
1 <= arr1.length, arr2.length <= 10000 <= arr1[i], arr2[i] <= 10^9