Min Cost Climbing Stairs

Given an integer array cost where cost[i] is the cost of step i, return the minimum cost to reach the top of the floor. You may climb one or two steps at a time. This is a standard choice-DP problem with a min-cost recurrence.

Input Format

cost = cost of each step

Output Format

minimum total cost to reach the top

Constraints

  • 2 <= cost.length <= 1000; 0 <= cost[i] <= 999

Examples

Example 1:

Input:

cost = [10,15,20]

Output:

15

Explanation:

Take step 1 and then jump to the top.

Example 2:

Input:

cost = [1,100,1,1,1,100,1,1,100,1]

Output:

6

Explanation:

The cheapest path avoids expensive steps.

Loading...
Min Cost Climbing Stairs - Dp Knapsack