Skip to content
Decoder

Min Cost Climbing Stairs

Easy

Problem

cost[i] is the price of standing on step i. You may start on step 0 or step 1. After paying for a step, you climb 1 or 2 steps. The top is just past the last step. Return the cheapest total cost to reach the top.

Example 1

Input
cost = [10, 15, 20]
Output
15
Why
start on 1, jump 2 to the top

Example 2

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

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.