Practice

Problem 8 of 10

Problem · Medium · 20 min

Climb the stairs

  • Medium
  • Dynamic programming
  • Math

A stair has steps steps. You start at the bottom. With one move you climb 1, 2 or 3 steps. You want to reach the top exactly.

Write count_ways(steps). It returns the number of different sequences of moves that reach the top.

  • The order of the moves matters. 1 + 2 and 2 + 1 are two different ways.
  • For steps equal to 0, there is one way: make no move.
  • steps is a whole number from 0 to 40.

Examples

Call Result
count_ways(3) 4
count_ways(4) 7
count_ways(0) 1

Tasks

2 to do

  1. Task 1, not checked yet. Make count_ways pass the example tests.

  2. Task 2, not checked yet. Make count_ways pass the hidden tests.

Task 1 of 2

Make count_ways pass the example tests.

All tasks

main.py

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.