v9.1.1
Menu

Climbing Stairs

easyFREEDynamic ProgrammingBlind 75

You are climbing a staircase with n steps. Each time you can climb 1 or 2 steps. How many distinct ways can you reach the top?

Example

Input
3
Output
3
Reasoning
  • To reach the top of a staircase with 3 steps, we can climb 1 or 2 steps at a time, so we consider all possible combinations of 1 and 2 steps.
  • The distinct ways to reach the top are:
    • 1 step + 1 step + 1 step
    • 1 step + 2 steps
    • 2 steps + 1 step
  • We count the number of distinct ways, which is 33 in this case.
  • The final output is the total count of distinct ways, which is 3\boxed{3}.

Constraints

  • 1 <= n <= 45

Learn this in

More from Blind 75

solution.py

Test results

Sign in to run your code against the test cases.