← All problems

Min Cost Climbing Stairs

Easy dynamic programmingarrays LeetCode ↗
You are given an integer array cost where cost[i] is the price of stepping on stair i. Starting from stair 0 or stair 1 for free, each move you may climb 1 or 2 stairs, paying the cost of the stair you land on. Find the minimum cost to reach the top (one step beyond the last stair).

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), space O(1).

Common pitfalls

  • Paying cost[0]/cost[1] for the starting stair (starting is free).
  • Returning dp[n-1] instead of min(dp[n-1], dp[n-2]).
  • Allocating a full dp array when two variables suffice.

Your solution

Log in to save your code and track progress.