Maximum Xor Product

Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2^n.

Since the answer may be too large, return it modulo 10^9 + 7.

Note that XOR is the bitwise XOR operation.

Example 1
Inputa = 12, b = 5, n = 4
Output98
For x = 2, (a XOR x) = 14 and (b XOR x) = 7, so the maximum product is 98.
Example 2
Inputa = 6, b = 7, n = 5
Output930
For x = 25, (a XOR x) = 31 and (b XOR x) = 30, so the maximum product is 930.

Constraints

  • 0 <= a, b < 2^50
  • 0 <= n <= 50

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate