Reported September 2026
Microsoftmath

Count Digit Replacements with No Equal Adjacent Digits

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

Microsoft reported this one in September 2026, and it looks scarier than it is. You get a digit string with question marks, and you count fills where no two neighbors match, modulo 10^9 + 7. Strip the story and it's a counting problem. Each ? has 10 digits minus whatever its neighbors forbid, and runs of consecutive question marks chain together. The two samples (72 and 90) show the idea but hide the trap when ?s sit side by side. If the OA timer is running and your head goes blank, StealthCoder is the invisible safety net that reads the problem and hands you a working solution. Know the shape first, though.

The problem

You are given a string s containing digits from 0 through 9 and question marks.
Replace every ? with one digit so that no two adjacent digits are equal. Return the number of valid replacements modulo 10^9 + 7.

Function
getNumOfWays(s: String) → int

Examples
Example 1
s = "1?3?"
return = 72
The first question mark may be any digit except 1 and 3, giving 8 choices. The last may be any digit except 3, giving 9 choices. Therefore the result is 8 * 9 = 72.
Example 2
s = "??"
return = 90
The first position has 10 choices, and the second has 9 choices different from the first.

Constraints
1 <= s.length <= 10^5
s contains only digits from 0 through 9 and ?.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The reduction: split the string into runs of ?. A run with no fixed neighbors of length k gives 10 * 9^(k-1). A run touching one fixed digit gives 9^k. A run between two fixed digits needs care, because the last ? must dodge both its left ? and the right digit. Don't multiply per-position choices blindly. That's the pitfall, and example 1 only works because its ?s are isolated. The safe route is a DP over positions with 10 states, the last digit placed. Each step sums the previous states except the same digit, and fixed digits zero out every other state. That's O(10n), well inside 10^5. Check first: if two fixed digits are adjacent and equal, return 0. Take the mod at every addition. If you freeze on the recurrence during the live OA, StealthCoder is the hedge that gives you the DP when you need it.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Count Digit Replacements with No Equal Adjacent Digits 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Digit Replacements with No Equal Adjacent Digits FAQ

What's the trick in this Microsoft OA question?+

Treat it as a chain counting problem. Each position depends only on the previous digit, so a 10-state DP works. For each position, track how many ways end in each digit. A ? allows any digit except the previous one. A fixed digit keeps only its own state.

Why can't I just multiply choices per question mark?+

That only works when the ?s are isolated, like example 1. When two ?s are adjacent, the second's options depend on what the first picked. A ? between a ? and a fixed digit has two constraints that overlap. Use DP, or closed forms per run, to avoid miscounting.

What edge cases should I test before submitting?+

Two equal fixed digits next to each other, which must return 0. A string of all ?s, such as "??" giving 90. A single character, either ? giving 10 or a digit giving 1. Also a 10^5 length all-? input to confirm the modulo is applied everywhere.

How hard is this problem really?+

Easy to medium. The DP is short, about ten lines, and the complexity is O(10n). The difficulty is spotting that neighbors interact and remembering the modulo. If you've written a 'count strings with no equal adjacent characters' DP before, this is the same thing with fixed digits.

How do I prepare for this in 48 hours?+

Write the 10-state DP from scratch once. Then hand-check both examples, 72 and 90, and add the adjacent-equal-fixed-digits case. Practice the rolling update using total sum minus the same-digit state, which cuts the inner loop. Keep every addition under the mod to avoid overflow bugs in typed languages.

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