All problems
Min Cost Climbing Stairs
Problem
Given cost where cost[i] is the fee to stand on step i, return the minimum total cost to reach the top just past the last step.
You may start at step 0 or step 1, and each move advances one or two steps. The recurrence is cur = cost[i] + min(previous two best values).
Hint
The top is one step past the end, so the answer is the cheaper of the last two states.
Test cases
case 1
in: [[10,15,20]]
expected: 15
case 2
in: [[1,100,1,1,1,100,1,1,100,1]]
expected: 6
case 3
in: [[0,0]]
expected: 0
case 4
in: [[1,2]]
expected: 1
case 5
in: [[5,5]]
expected: 5
Starter codePython
def min_cost_climbing_stairs(cost):
# Your code here
pass5 test cases · run your code against them in the editor