Problem · Array

Maximum XOR Between Two Arrays

Learn this problem
HardInMobi logoInMobiFULLTIMEONSITE INTERVIEW

Problem 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[]) → int

Examples

Example 1

arr1 = [6,6,0,6,8,5,6]arr2 = [1,7,1,7,8,0,2]return = 15

Choosing 8 from arr1 and 7 from arr2 gives 8 xor 7 = 15.

Example 2

arr1 = [25,10,2]arr2 = [8,5,3]return = 28

Choosing 25 and 5 gives 25 xor 5 = 28, the largest cross-array value.

Constraints

  • 1 <= arr1.length, arr2.length <= 1000
  • 0 <= arr1[i], arr2[i] <= 10^9

More InMobi problems

drafts saved locally
public int maximumXorBetweenArrays(int[] arr1, int[] arr2) {
    // write your code here
}
arr1[6,6,0,6,8,5,6]
arr2[1,7,1,7,8,0,2]
expected15
checking account