Question: c + + You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2

c ++ You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example 1:
Input: n =2
Output: 2
Explanation: There are two ways to climb to the top.
1.1 step +1 step
2.2 steps
Example 2:
Input: n =3
Output: 3
Explanation: There are three ways to climb to the top.
1.1 step +1 step +1 step
2.1 step +2 steps
3.2 steps +1 step
Constraints:
1<= n <=45
Seen this question in a real interview before?
1/5
Yes
No
Accepted
3.2M
Submissions
6.1M

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!