Min Cost Climbing Stairs

Dynamic Programming, problem 2 of 9

Min Cost Climbing Stairs

Easy

LC #746

1d dp

Not attempted yet

cost[i] is the price of stepping off step i. After paying you climb 1 or 2 steps. You may start on step 0 or step 1 for free. The top is just past the last step (index len(cost)).

Return the minimum total cost to reach the top.

Example 1

Input: cost = [10, 15, 20]
Output: 15
start on step 1, pay 15, climb 2

Example 2

Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
Output: 6

Example 3

Input: cost = [5, 10]
Output: 5

Constraints

  • 2 ≤ len(cost) ≤ 1000
  • 0 ≤ cost[i] ≤ 999

Python

Loading draft…

Test results

7 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 4 hidden

Run examples, then submit all tests.