Skip to main content
← Problem catalogue Understand the pattern. Try it yourself. Review the solution. Practice this pattern →
Easy Dynamic Programming High frequency Solution Available Practice Mode

Min Cost Climbing Stairs LeetCode Solution

Tags: #Array #Dynamic Programming

Approach Summary

dp[i] = cost[i] + min(dp[i-1], dp[i-2]). Result is min(dp[n-1], dp[n-2]).

Practice Mode

Solve it yourself before revealing the code

DSA interviews test reasoning from brute force to optimal. Think through the constraints first.

Algorithmic Pattern

Master the Dynamic Programming Pattern

View Pattern Guide →

Study the core invariant, step-by-step decision framework, and common interview traps for the Dynamic Programming pattern.

Framework: Dynamic Programming • Interview Prep: Tested at FAANG • Explore all Dynamic Programming problems & invariants →

How to Recognize This Pattern

  • Pay cost to leave stair, can start at 0 or 1
  • Classic 1D DP with two choices

Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)

Tags

Array Dynamic Programming

Frequently Asked Questions

What is the optimal time and space complexity for Min Cost Climbing Stairs?
The optimal solution for Min Cost Climbing Stairs achieves O(n) runtime complexity and requires O(1) auxiliary space. Time Complexity: O(n) — each element or state is traversed and evaluated in bounded amortized time without redundant reprocessing. Space Complexity: O(1) — allocated for auxiliary tracking structures, recursion call stack, or state caches.
How do I identify that Min Cost Climbing Stairs requires the Dynamic Programming pattern?
In technical interviews, look for key problem signals: Pay cost to leave stair, can start at 0 or 1; Classic 1D DP with two choices. Recognizing these invariants allows you to bypass naive brute-force exhaustive search in favor of Dynamic Programming strategy.
What critical edge cases must be handled in Min Cost Climbing Stairs?
Essential edge cases to verify include: Key recognition trigger: Pay cost to leave stair, can start at 0 or 1.; Constraint condition: Classic 1D DP with two choices.; Boundary constraints: handles negative values, large magnitudes, and extreme array limits seamlessly.; Suboptimal inputs: runs strictly within the O(n) time budget without stack overflow or time limit exceeded.. Always walk through these scenarios with your interviewer before coding.
Which tech companies frequently ask Min Cost Climbing Stairs?
Min Cost Climbing Stairs is a Easy-difficulty question tagged with high recurrence. It is actively asked in technical screening and onsite interview loops at Amazon, Google, Adobe.
Buy me a coffee
Daily Practice
0/0