Climbing Stairs

Python data engineering interview problem. Difficulty: advanced. Pattern: Dynamic Programming. About 18 minutes. Part of the Pro drill bank.

Number of ways to climb n stairs taking 1 or 2 steps. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A workflow has n steps, and each move can advance one or 2 steps. Count the different move sequences. Return the number of ways to reach exactly step n using only one-step and 2-step moves. Order matters, so 1 then 2 differs from 2 then 1. Write climb_stairs(n: int) -> int. For n = 3, the sequences are 1+1+1, 1+2 and 2+1, giving 3. The starter file already contains the function name, harness and print lines. Keep them and fill only the function body.

Requirements

  • Count ordered sequences.
  • Use only steps of size 1 or 2.
  • Return an integer count.

Constraints

  • n is a non-negative integer.
  • There is one way to reach step 1 and one empty way to reach step 0.

Examples

Input: climb_stairs(3) Output: 3 Three sequences.

Topics: lakebench, python, dp, fibonacci.

More Python interview questions · All interview problems · Learn data engineering

advanced

Climbing Stairs

Interview-style drill: Number of ways to climb n stairs taking 1 or 2 steps.

Implement `climb_stairs(n: int) -> int`. Example: `n=3` → `3` (1+1+1, 1+2, 2+1). Keep the harness.