Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Climbing Stairs

Easy
dynamic-programmingmathmemoization

You climb a staircase of n steps, taking 1 or 2 steps at a time. How many distinct ways can you reach the top?

Input: one line, the integer n. Output: the number of distinct ways.

Example 1
Input:
2
Output:
2

1+1 or 2.

Example 2
Input:
3
Output:
3

1+1+1, 1+2, 2+1.

Constraints

  • 1 ≤ n ≤ 45
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.