Problem · Bit Manipulation

XOR Multiplication

MediumMicrosoftOA
See Microsoft hiring insights

A new circuit has been designed that takes three inputs: A, B, and N.

The task is to find an integer X such that X < 2^N and the product of (A XOR X) and (B XOR X) is maximized.

Return the result modulo 10^9 + 7.

Note that XOR represents the bitwise XOR operator.

Examples
01 · Example 1
A = 4
B = 6
N = 3
return = 35

We can choose X = 3: (A XOR X) = 7 and (B XOR X) = 5. The product is 35, and 35 modulo 10^9 + 7 is 35.

Constraints
  • 0 <= N <= 30
  • 1 <= A < 2^N
  • 1 <= B < 2^N
More Microsoft problems
drafts saved locally
public int xorMultiplication(int A, int B, int N) {
  // write your code here
}
A4
B6
N3
expected35
checking account