Boss lesson · Unit 01
Min cost climbing stairs
Choices combined with min, solved end to end
What you practise
- Choices combined with
min
Try a question from this lesson
Pick one
Each stair has a toll. You climb 1 or 2 stairs per move, starting on stair 0 or 1; the top is past the last stair. Tolls: [1, 100, 1, 1]. Cheapest total?
Correct answer
2
Why
Stand on stair 0 (pay 1), jump to stair 2 (pay 1), then jump two stairs past stair 3 to the top: total 2. Stopping on stair 3 as well would cost 3, and stair 1 is the one to avoid.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The toll staircase
Every stair charges a toll: cost[i] is what you pay each time you stand on stair i.
From a stair you climb 1 or 2 stairs. You may start on stair 0 or stair 1. The top is the floor just past the last stair, and it is free.
Find the cheapest way to the top. For tolls [10, 15, 20] it is 15: start on stair 1, pay 15, and jump two stairs to the top.
10 more exercises in the app
- 3× multiple choice
- 1× order the lines
- 1× type the answer
- 2× fill the blanks
- 2× true or false
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.