Distinct Number Line Moves
Updated
Problem statement
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) → intExamples
Example 1
s = "rrlrlr"n = 6x = 1y = 2return = 7Constraints
1 <= s.length <= 10^50 <= x, y, n <= 2500scontains only'l'and'r'.
More Microsoft Online Assessment questions
- Authentication SystemOA · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
- Minimum Cost K-Capable ModelsOA · Seen Nov 2026
- Find Available Meeting RoomsOA · Seen Oct 2026
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)