Skip to main content
All Visualizers
#LC 70•Dynamic Programming•Easy

Climbing Stairs

Count the number of distinct ways to reach the top of a staircase when each move takes one or two steps.

Understand the problem

Count the number of distinct ways to reach the top of a staircase when each move takes one or two steps.

Example 1

Input: {"n": 5}

Output: 8

Follow the trace to see how the algorithm reaches this result.

Constraints

  • Use the input format shown in the example.
Think first

What information should you keep so you can solve the next step efficiently?

Pattern tags:Dynamic programmingOverlapping subproblems
Time: O(n)Space: O(n)
Step 1 of 5 • Use Left/Right arrows or Space to control