Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Ways to Reaching the n'th Stair

Medium Acceptance 50% Points 30

There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. Your task is to count the number of ways, the person can reach the top (order does matter).

Examples
Example 1

Example 1

Input: n = 1

Output: 1

Explanation: There is only one way to climb 1 stair.

Example 2

Example 2

Input: n = 2

Output: 2

Explanation: There are 2 ways to reach 2th stair: {1, 1} and {2}.

Example 3

Example 3

Input: n = 4

Output: 5

Explanation: There are five ways to reach 4th stair: {1, 1, 1, 1}, {1, 1, 2}, {2, 1, 1}, {1, 2, 1} and {2, 2}.

Constraints
  • 1 = n = 44
Topics
Dynamic Programming
Companies
Amazon Microsoft Adobe Flipkart
Added 13 Aug 2025 50% acceptance
Ln 1, Col 1Sign in to save your code
1
1