Reported October 2025
Microsoftdynamic programming

Distinct Number Line Moves

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 October 2025, and it looks like a path-walking puzzle but it isn't. It reduces to counting distinct subsequences of a string, with a position constraint bolted on. Distinct means you can't just count index choices, or you'll blow past the answer on the example (7 for rrlrlr). If your OA lands in the next day or two, know the shape now: a DP over the string with a position dimension, plus the classic dedupe trick. StealthCoder sits invisibly as a safety net if the dedupe logic slips away mid-assessment.

The problem

You are given a number line with positions labeled from 0 to n, a string s of move instructions, and two positions x and y.
A move instruction 'l' moves one step left, and 'r' moves one step right. You may choose any subsequence of s, preserving order, and execute that subsequence starting from position x. The position must always remain between 0 and n.
Two subsequences are considered the same if their resulting move strings are identical, even if they came from different indices of s.
Return the number of distinct subsequence move strings that take you from x to y, modulo 1_000_000_007.

Function
distinctMoves(s: String, n: int, x: int, y: int) → int

Examples
Example 1
s = "rrlrlr"
n = 6
x = 1
y = 2
return = 7

Constraints
1 <= s.length <= 10^5
0 <= x, y, n <= 2500
s contains only 'l' and 'r'.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: count distinct subsequences, where the state is your current position on the line. Let dp[p] be the number of distinct move strings ending at position p. Process characters of s left to right. For each character c, the new strings are those formed by appending c to existing strings, shifting positions by -1 or +1 and dropping anything outside 0..n. To dedupe, use the standard distinct-subsequence rule: for each character, keep the previous contribution and subtract what that same character added last time, so only strings new to this character get added. The empty string counts at x. Pitfall: naive DP is O(len * n), about 2.5 * 10^8 with the limits, so keep it tight, use flat arrays, and mod carefully. Negative values after subtraction need fixing. Answer is dp[y]. If the dedupe subtraction confuses you under pressure, StealthCoder can talk you through it live.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Distinct Number Line Moves 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Distinct Number Line Moves FAQ

What's the real trick in Distinct Number Line Moves?+

It's distinct-subsequence counting with a position state. Track how many distinct move strings end at each position, and use the last-occurrence dedupe so identical strings from different indices aren't counted twice. The answer is the count at position y.

Why can't I just count index subsequences?+

Because the problem says two subsequences are the same if their move strings match. Index-based counting overcounts. On the example rrlrlr from 1 to 2 the answer is 7, and a raw count of index choices will give you more.

How do I handle the boundaries 0 and n?+

Any move that would leave 0..n is simply invalid. When you shift dp for an 'l', position 0 can't move left, and for an 'r', position n can't move right. Those states contribute nothing to the new strings.

Will a brute force pass?+

No. s can be 10^5 long, so enumerating subsequences is out. You need a DP that processes each character once, updating an array of size n+1. Watch the constant factor, since length times n is large.

How do I prepare for this in 48 hours?+

Solve the classic distinct subsequences counting problem until the last-occurrence subtraction is automatic. Then add a position array and practice the modulo handling, especially negative values after subtraction. That covers this Microsoft question's core.

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