You are climbing a staircase that has n steps to reach the top. On each move you may advance either one step or two steps.
Return the total number of distinct sequences of moves that take you from the ground to the very top of the staircase.
Example 1
Input: n = 2
Output: 2
There are two ways: take a single step twice (1 + 1), or take one double step (2).
Example 2
Input: n = 3
Output: 3
The three orderings are 1 + 1 + 1, 1 + 2, and 2 + 1.
Constraints
1 <= n <= 45See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI