Climbing Stairs

EasyDynamic ProgrammingDynamic Programming

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

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?

Examples

Input: n = 2
Output: 2
There are two ways to climb to the top: 1 step + 1 step, or 2 steps.
Input: n = 3
Output: 3
1+1+1, 1+2, 2+1.

Constraints

  • 1 <= n <= 45

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More Dynamic Programming problems