Min Cost Climbing Stairs

A staircase has n steps, and cost[i] is the price you pay each time you step on step i. After paying for a step you may climb one or two steps up. You may begin on step 0 or on step 1. The top of the staircase is the position just past the last step (index n), and it costs nothing to arrive there.

Return the 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

Start on step 1 (index 1), pay 15, and jump two steps to the top.

Example 2

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

Step on the 1s and skip every 100 by jumping over it: 1 + 1 + 1 + 1 + 1 + 1 = 6.

Example 3

Input: cost = [0,0]
Output: 0

Free steps cost nothing.

JavaScript you'll use: Arrays: create, read, update Numbers, Math and integer tricks

/**
 * @param {number[]} cost
 * @return {number}
 */
function minCostClimbingStairs(cost) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.