FastPrepConstrained Jump Sequences
Problems/Constrained Jump Sequences

Constrained Jump Sequences

PhonePe logoPhonePe● HardFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits numeric bounds. The judged core task matches the visible source at about 98%.

There are n locations on a straight line, numbered from 1 through n. You begin at start, and a fixed spotlight is at spotlight.

Make exactly jumps consecutive jumps. For every jump from the current location x to the next location y, both rules must hold:

  • x != y.
  • |x - y| < |x - spotlight|.

Return the number of valid jump sequences modulo 10^9 + 7.

Function

countJumpSequences(n: int, start: int, spotlight: int, jumps: int) → int

Examples

Example 1

n = 5start = 2spotlight = 4jumps = 1return = 2

From location 2, the current distance to the spotlight is 2. The legal destinations are 1 and 3.

Example 2

n = 5start = 2spotlight = 4jumps = 2return = 2

The first jump can reach 1 or 3. Location 3 has no legal next destination, while location 1 can jump to 2 or 3. Therefore there are two sequences.

Example 3

n = 6start = 5spotlight = 3jumps = 2return = 2

The only valid two-jump sequences are 5 -> 6 -> 4 and 5 -> 6 -> 5.

Constraints

  • 2 <= n <= 2000
  • 1 <= start, spotlight <= n
  • 1 <= jumps <= 2000

More PhonePe problems

  • Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
  • K-th Smallest Value in a Sorted MatrixONSITE INTERVIEW · Seen Oct 2026
  • Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
All PhonePe interview questionsSee PhonePe hiring insights
Saved
class Solution {
    public int countJumpSequences(int n, int start, int spotlight, int jumps) {
      // write your code here
    }

}
Checking account…