Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Ways to Reaching the n'th Stair

Medium Acceptance 50.00% Points 30.00

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}.

Hints
Hint 1
NA
Constraints
  • 1 = n = 44
Companies
Amazon Microsoft Adobe Flipkart
Topics
Dynamic Programming
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions