Distinct Moves
Updated
Problem statement
Given a number line from 0 to n and a string denoting a sequence of moves,
determine the number of subsequences of those moves that lead from a given point x to end
at another point y. Moves will be given as a sequence of l and r
instructions. An instruction l = left movement, so from position j the new
position is j - 1, an instruction r = right movement, so from position
j the new position would be j + 1.
For example, given a number line from 0 to 6, and a sequence of moves
rrlrr, the number of subsequences that lead from 1 to 4 on the
number line is 3.
Complete the function distinctMoves in the editor.
distinctMoves has the following parameter(s):
s: a string that represents a sequence of movesn: an integer that represents the upper bound of the number linex: an integer that represents the starting pointy: an integer that represents the ending point
int: the number of distinct subsequences modulo 10^9 + 7
Function
distinctMoves(s: String, n: int, x: int, y: int) → intExamples
Example 1
s = "rrlrlr"n = 6x = 1y = 2return = 7N/A
Constraints
1 <= |s| <= 10^30 <= x, y, n <= 2500
More Flexport interview questions
- Apply Operations to Make a String EmptyPHONE SCREEN · Seen Nov 2026
- Max Area of Island Without Changing the GridPHONE SCREEN · Seen Nov 2026
- Choose the Next Hidden-Word GuessONSITE INTERVIEW · Seen Jul 2026
- Count Good SubsequencesOA · Seen Jun 2024
- Hotspot ConnectionsOA · Seen Jun 2024
- Throw The BallOA · Seen Jun 2024
- Matrix TraversalOA · Seen Feb 2024
- Collect PointsOA · Seen Feb 2024
- Malware SpreadOA · Seen Feb 2024
- Sum of All ValuesOA · Seen Feb 2024
Similar questions at other companies
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
- Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions