Climbing Stairs With K Steps

Given n stairs and an integer k, return the number of ways to reach the top if each move can climb between 1 and k steps. Pattern focus: Linear Recurrence DP. The answer at each position is the sum of the previous k states.

Input Format

n = number of stairs, k = maximum step size

Output Format

number of distinct ways to reach the top

Constraints

  • 1 <= n <= 10^5; 1 <= k <= 10^5

Examples

Example 1:

Input:

n = 4
k = 2

Output:

5

Explanation:

This matches the classic 1-or-2 step staircase count.

Example 2:

Input:

n = 4
k = 3

Output:

7

Explanation:

Allowing a 3-step jump increases the count.

Loading...
Climbing Stairs With K Steps - Dp 1d DSA Problem