TRT
Sign in
easyAdvancedLeetCode#bottom-up table

Min cost climbing stairs

Find the cheapest way to the top of a staircase where each step has a cost, filling a table from the bottom up.

The Runtime Theory Team1 min read
Taught inBottom-up tablesPro — members onlyInstead of recursing and caching, fill an array of answers in an order where every value a cell needs has already been computed. No recursion, no lookups, and the structure of the table becomes visible.
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

incost = [10, 15, 20]

out15

incost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]

out6

incost = [0, 0, 0]

out0

cost[i] is the cost of stepping off step i. You may start on step 0 or 1 and climb one or two steps at a time. Return the minimum cost to reach the top, just past the last step.

Before you code

Write the five decisions first: what dp[i] means, the recurrence, the base cases, the order and where the answer is.

Hints

  1. dp[i]: cheapest cost to stand on step i; dp[0] = dp[1] = 0.
  2. dp[i] = min(dp[i-1] + cost[i-1], dp[i-2] + cost[i-2]).
  3. The answer is dp[n]. Then reduce it to two variables.

Production & complexity notes

When solving Min cost climbing stairs on LeetCode (easy), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Bottom-up tables to reinforce the underlying pattern.

What it practices

Turning a recurrence into a table, from Bottom-up tables.

Not started

Sign in to save your learning progress.

Sign in to save