1119. Min Cost Climbing Stairs

EasyDynamic Programming1D DP

Given an array cost where cost[i] is the cost of stepping on stair i, you may start at stair 0 or 1 and climb one or two stairs at a time. Return the minimum cost to reach the top (just past the last stair). The input is JSON {cost}.

Input: JSON {cost}.

Output: Integer — the minimum cost to reach the top.

Examples

Example 1
Input: {"cost":[10,15,20]}
Output: 15
Explanation: Start at index 1 and step to the top.
Example 2
Input: {"cost":[1,100,1,1,1,100,1,1,100,1]}
Output: 6
Explanation: Skip the expensive stairs.
Example 3
Input: {"cost":[0,0]}
Output: 0
Explanation: No cost.

Constraints

Asked by

AmazonGoogleMetaBloombergMicrosoft
Solve this problem in the editor →