ExamAdda Logo

Climbing Stairs

Easy

You are climbing a staircase with n steps.

Each time you can either climb 1 step or 2 steps.

Return the number of distinct ways you can reach the top of the staircase.

Example 1

Input

n = 2

Output

2

Explanation

There are two ways to reach the top:

1 + 1

  2

Example 2

Input

n = 3

Output

3

Explanation

There are three ways:

1 + 1 + 1
1 + 2
2 + 1

Constraints

1 <= n <= 45

Hints:

Hint 1

To reach step n, you must come from either:

  • step n - 1
  • step n - 2
Hint 2

Therefore:

ways[n] = ways[n - 1] + ways[n - 2]

 

 

Auto
Loading editor...
Input

Expected Output