Min Cost Climbing Stairs
Problem
You are given an array cost where cost[i] is the price of stepping on stair i. Once you pay for a stair you may move up either one or two stairs. You may begin on stair 0 or stair 1 without paying anything to get there (you pay for a stair only when you step on it). The goal is the landing just past the last stair, which costs nothing. Return the minimum total you must pay to reach the landing.
costhas at least two stairs and up to about a thousand.- Each stair's cost is a non-negative integer under a thousand.
Examples
cost = [8, 12, 25]→12. Start on stair 1 (pay 12) and jump two stairs to the landing.cost = [2, 50, 2, 2, 2, 50, 2, 2, 50, 2]→12. Start at stair 0 and take stairs 0, 2, 4, 6, 7, 9 (all cost 2), skipping every 50.cost = [7, 7]→7. Start on either stair and step off.
Hints
- To reach any stair
i, you must have come fromi-1ori-2. Which of those two should you have come from? - The landing is one stair past the end; treat it like a stair with cost 0.
min_to[i] = cost[i] + min(min_to[i-1], min_to[i-2]), withmin_to[0] = cost[0]andmin_to[1] = cost[1], and the answer ismin(min_to[n-1], min_to[n-2]).
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.