Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reach a Position in Exactly k Steps

Number of Ways to Reach a Position in Exactly k Steps asks for the number of distinct left-or-right sequences moving from start to target on an infinite number line in exactly k steps, modulo a large prime.

Statement

You are given two positive integers startPos and endPos. Initially, you are positioned at startPos on an infinite number line. In each step, you can move either 11 unit to the left or 11 unit to the right.

Return the total number of distinct ways to reach position endPos after moving exactly k steps. Since the answer may be large, return it modulo 109+710^9 + 7.

Note: Two ways are considered different if the sequence of chosen directions at each step is not identical.

Constraints:

  • 1≤1 \leq startPos, endPos, k ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reach a Position in Exactly k Steps

Number of Ways to Reach a Position in Exactly k Steps asks for the number of distinct left-or-right sequences moving from start to target on an infinite number line in exactly k steps, modulo a large prime.

Statement

You are given two positive integers startPos and endPos. Initially, you are positioned at startPos on an infinite number line. In each step, you can move either 11 unit to the left or 11 unit to the right.

Return the total number of distinct ways to reach position endPos after moving exactly k steps. Since the answer may be large, return it modulo 109+710^9 + 7.

Note: Two ways are considered different if the sequence of chosen directions at each step is not identical.

Constraints:

  • 1≤1 \leq startPos, endPos, k ≤1000\leq 1000