Climbing Stairs
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
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]
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 23, 2026
Last updated
Aug 23, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output