Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 746 Min Cost Climbing Stairs - Transition

Choose cheaper path

The recurrence is: dp[i]=min(dp[i1]+cost[i], dp[i2]+cost[i])dp[i] = \min(dp[i-1] + cost[i], \ dp[i-2] + cost[i]) You pick the cheaper route. The final answer is min(dp[n-1], dp[n-2]) because you can take a final jump from either of the last two steps to reach the top (index n).

This mirrors Fibonacci's structure but replaces addition with min and considers costs. This time, you're reducing cost instead of counting! This transition captures the relationship between subproblems.