Skip to main content

Min Cost Climbing Stairs

Find minimum cost to climb to the top Can climb 1 or 2 steps, start from step 0 or 1 Example: [10,15,20] => 15

You are given an array cost with at least two elements, where cost[i] is the non-negative price of leaving stair i. After paying it you may climb one or two stairs, and you may start on either stair 0 or stair 1. Return the minimum total cost to reach the top, the position just past the last stair. For example, [10,15,20] costs 15.

Examples

You write

min_cost_climbing_stairs(cost: List[int])

  1. Example 1

    Input
    [10,15,20]
    returns
    15
  2. Example 2

    Input
    [1,100,1,1,1,100,1,1,100,1]
    returns
    6

The pattern behind it

Arrays & Hashing

I reach for it when

  • You catch yourself scanning the array again for every element.
  • The problem asks about duplicates, pairs, counts or groups.

Say this before you type. Say what the key is and what the value remembers, before you write the loop.

All 127 Arrays & Hashing problems

Dynamic Programming

I reach for it when

  • Brute force repeats the same subproblem.
  • You are asked for a count, a minimum or a maximum.

Say this before you type. Say the state in one sentence, then say which smaller states it reads from.

All 37 Dynamic Programming problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Min Cost Climbing Stairseasy