All problems
Climbing Stairs
Problem
Return the number of distinct ways to climb a staircase of n steps when each move is either 1 or 2 steps.
The count follows the Fibonacci recurrence ways(n) = ways(n-1) + ways(n-2) with ways(0) = 1 and ways(1) = 1. Assume n >= 0.
Hint
The number of ways to reach step n equals the ways to reach n-1 plus the ways to reach n-2.
Test cases
case 1
in: [1]
expected: 1
case 2
in: [2]
expected: 2
case 3
in: [3]
expected: 3
case 4
in: [5]
expected: 8
case 5
in: [10]
expected: 89
Starter codePython
def climb_stairs(n):
# Your code here
pass5 test cases · run your code against them in the editor