Reported June 2026
Microsoftbit manipulation

XOR Multiplication

Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Microsoft OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Microsoft OA, reported in June 2026, is taking the modulo before comparing products. The task looks like a brute force over X, but N goes up to 30, so that's over a billion candidates. It's a bit manipulation problem in disguise. You pick X bit by bit and decide where each bit pushes the two factors. If you've got the OA invite and the logic isn't clicking, StealthCoder is the invisible backup that reads the problem on screen and hands you a working solution if you blank.

The problem

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.

Function
xorMultiplication(A: int, B: int, N: int) → int

Examples
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

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: (A^X) + (B^X) isn't fixed, but the product of two numbers with a roughly constant sum is largest when they're close. Look at each bit below N. Where A and B have the same bit, setting X's bit to the opposite makes both factors 1 at that position, so always do that. Where A and B differ, exactly one factor gets a 1 there no matter what X is. Give that 1 to the currently smaller factor, starting from the highest differing bit, to keep them balanced. The first differing bit goes to either side, then every later one goes to whichever is smaller. The pitfall is applying mod 10^9+7 during the comparison. Compare the exact values (Python ints, or long long carefully, since values stay below 2^30 each), and only mod the final product. Also handle N = 0. StealthCoder is your hedge if the greedy argument escapes you mid-assessment.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill XOR Multiplication cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Microsoft's OA.

Microsoft reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

XOR Multiplication FAQ

What's the trick in XOR Multiplication?+

Treat it as a greedy over bits. Where A and B share a bit, set X to flip both to 1. Where they differ, one factor gets the 1 regardless, so assign it to whichever factor is currently smaller. Keeping the two numbers close maximizes the product.

Why can't I brute force every X?+

N goes up to 30, so X ranges over more than a billion values. Each needs a multiplication and comparison. That's too slow for most OA limits. The bit-by-bit greedy runs in O(N), which is trivial.

When do I apply the modulo?+

Only at the end. Comparing products or factors after taking mod 10^9+7 gives wrong answers, because modded values lose ordering. Each factor is under 2^30, so compare the real values and return (a * b) mod 10^9+7 once.

How hard is this Microsoft problem really?+

Medium. The code is short, maybe 10 lines. The difficulty is seeing why balancing the two factors maximizes the product. Once you see that, the implementation is easy. Edge cases are N = 0 and the case where A equals B.

How do I prepare in 48 hours?+

Work through the sample by hand. A=4, B=6, N=3 gives X=3 and 35. Write out the bit columns, trace the greedy, and confirm it. Then review similar bit-by-bit decisions: maximize XOR, flip bits, and mask tricks. Practice writing it without looking.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Microsoft.

OA at Microsoft?
Invisible during screen share
Get it