15% off all plans & roadmaps Use code
See plansLeetCode 746 · Solution & editorial
You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.
Min Cost Climbing Stairs is a Dynamic Programming (DP) Patterns problem, in the 1D Array (Fibonacci Style) subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Solve problems with Fibonacci-like recurrence: climbing stairs, house robber, decode ways.
The reference solution runs in O(n) time and O(1) space.
Min Cost Climbing Stairs has been reported in interviews at Adobe, Amazon, Apple, Bloomberg, Goldman Sachs, Google, Microsoft, Uber.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Min Cost Climbing Stairs is a Dynamic Programming (DP) Patterns problem, in the 1D Array (Fibonacci Style) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.