Min Cost Climbing Stairs

Asked byAmazonAdobeBloomberg

Problem

Given an array where cost[i] is the cost of stepping on stair i, you may start from step 0 or step 1 and climb one or two steps at a time. Return the minimum cost to reach the top (one step past the last stair).

Examples

Example 1
Input:cost = [10,15,20]
Output:15
Start at index 1, pay 15, and step directly to the top.
Example 2
Input:cost = [1,100,1,1,1,100,1,1,100,1]
Output:6

Constraints

  • 2 <= cost.length <= 1000

Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.

Solve on FeatCode →

How to approach it: the 1-D Dynamic Programming pattern

Break a problem into overlapping subproblems along a single dimension — like "the answer up to index i" — solve each one once, and reuse the result instead of recomputing it.

Look for this pattern when

  • A greedy or purely recursive approach recomputes the same subproblem repeatedly.
  • The problem asks for a count, a minimum/maximum, or a yes/no reachability over a sequence, where the answer at position `i` depends on answers at earlier positions.

Read the full 1-D Dynamic Programming guide →

Video walkthroughs

Original problem on LeetCode ↗

More 1-D Dynamic Programming problems