InterviewHubPRO
Section Overview
Q92

Question 92 of 100

Part 11: Dynamic Programming & Knapsack (91 - 100)

92%
DSA Patterns (Multi-Lang)•Part 11: Dynamic Programming & Knapsack (91 - 100)

Min Cost Climbing Stairs.

In Simple Words: Work backwards from step $N-3$ down to 0: cost[i] += min(cost[i + 1], cost[i + 2]). Answer is min(cost[0], cost[1]).

  • Time: $O(N)$ | Space: $O(1)$
Multi-Language Solutions
Switch tabs or choose All
def minCostClimbingStairs(cost: list[int]) -> int:
    for i in range(len(cost) - 3, -1, -1):
        cost[i] += min(cost[i + 1], cost[i + 2])
    return min(cost[0], cost[1])