Trains the technique from
LeetCode 2939Maximum Xor ProductThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two meters hold the non-negative readings a and b. A calibration pulse is labelled by one non-negative integer x smaller than 2^n. Firing the pulse leaves each meter showing its own reading combined with x under bitwise exclusive-or. A pulse can therefore flip any chosen set of the n lowest bit positions, and it flips the very same positions in both meters.
Fire the pulse once, with x chosen freely in the range 0 <= x < 2^n. Among all allowed choices, take the largest product of the two resulting readings, reduce that product modulo 1000000007, and return the reduced value. The comparison that picks the largest uses the exact products, not the reduced ones.
Example 1
The pulse may flip the three lowest bits. With `x = 1` the readings become `9 XOR 1 = 8` and `6 XOR 1 = 7`, and 8 * 7 = 56, which is smaller than the modulus and so is returned as it stands.
Example 2
Only the two lowest bits may flip, so `x` is one of 0, 1, 2 and 3. With `x = 3` the readings become 15 and 7, whose product is 105.
Example 3
Both readings are 3, so any pulse changes them identically. Leaving them alone with `x = 0` keeps the product at 9.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_xor_product(a: int, b: int, n: int) -> int:public int maximumXorProduct(long a, long b, int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.