Challenge: The Staircase Problem

In this lesson, you will work on an interesting problem that can be solved using dynamic programming.

We'll cover the following

Problem statement

Nick is standing next to a staircase that leads to his apartment. The staircase has n total steps; Nick knows he can climb anywhere between 1 and m steps in one jump. He thinks about how many ways there are to climb this staircase. He realizes it is a big number since there are a lot of possible combinations. So, he has asked you to write an algorithm for him that tells him the number of possible ways to climb a staircase given n (number of steps) and, m (number of steps covered in biggest jump).

Input

Your algorithm will take as input n, the number of steps in the staircase and, m, the number of steps covered in the biggest leap. Nick can jump any number of stairs between 1 and m.

n = 4
m = 2

Output

Your algorithm will return the number of possible ways to climb the staircase.

staircase(n, m) = 5

Look at the following visualization as a hint for the challenge.

Get hands-on with 1200+ tech skills courses.