Skip to content
EasyDpAI interview only

Climbing Stairs

Asked atamazongoogleappleadobetiktok

01 · Problem

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?

02 · Examples

Example 01
Input
n = 2
Output
2

Two ways: (1+1) or (2).

Example 02
Input
n = 3
Output
3

Three ways: (1+1+1), (1+2), or (2+1).

03 · Constraints

  • 011 <= n <= 45

04 · Optimal complexity

Time
O(n)
Space
O(1)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.