Min Cost Climbing Stairs

EasyDynamic Programming1d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an array cost where cost[i] is the price of standing on step i of a staircase. After paying for a step you may climb either one or two steps. You may start on step 0 or step 1 for free (you still pay the cost of the step you stand on). The top of the staircase is the position just past the last step, index cost.length, and it costs nothing. Return the minimum total cost to reach the top.

Examples

Input: cost = [10,15,20]
Output: 15
Start on step 1, pay 15, and jump two steps to the top.
Input: cost = [1,100,1,1,1,100,1,1,100,1]
Output: 6
Stand on steps 0, 2, 4, 6, 7 and 9, paying 1 each, for a total of 6.

Constraints

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

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 1d dp problems