...

/

Climbing Stairs

Climbing Stairs

Try to solve the Climbing Stairs problem.

Statement

You are climbing a staircase. It takes n steps to reach the top. Each time, you can either climb 11 or 22 steps. In how many distinct ways can you climb to the top?

Constraints:

  • 11 \leq n 45\leq 45

Examples

canvasAnimation-image
1 / 2

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Technical Quiz
1.

What is the correct number of ways to climb to the top if n = 3?

A.

2

B.

3

C.

1

D.

4


1 / 2

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Note: As an additional challenge, we have intentionally hidden the solution to this puzzle.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4

Try it yourself

Implement your solution in the following coding playground.

We have left the solution to this challenge as an exercise for you. An optimal solution to this problem runs in O(n) time and takes O(n) space. You may try to translate the logic of the solved puzzle into a coded solution.

Python
usercode > main.py
def climb_stairs(nums):
# Replace this placeholder return statement with your code
return 1
Climbing Stairs

Access this course and 1200+ top-rated courses and projects.