FastPrepDistinct Moves
Problems/Distinct Moves

Distinct Moves

Flexport logoFlexport● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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):

  1. s: a string that represents a sequence of moves
  2. n: an integer that represents the upper bound of the number line
  3. x: an integer that represents the starting point
  4. y: 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) → int

Examples

Example 1

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

N/A

Constraints

  • 1 <= |s| <= 10^3
  • 0 <= 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
All Flexport interview questionsSee Flexport hiring insights
Saved
class Solution {
    public int distinctMoves(String s, int n, int x, int y) {
      // write your code here
    }

}
Checking account…