LeetCode · DP — 1D

Dynamic Programming — 1D Problem Set

Single-dimension DP: dp[i] depends on previous states. Start with simple recurrence, then optimise space.

Concept page: Dynamic Programming
DifficultyPatternProblemKey Insight
EasyfibonacciLC 70 · Climbing Stairsdp[i] = dp[i-1] + dp[i-2]. O(n) time, O(1) space.
Mediumtake/skipLC 198 · House Robberdp[i] = max(dp[i-1], dp[i-2] + nums[i]). O(n).
MediumcircularLC 213 · House Robber IITwo passes: [0..n-2] and [1..n-1], take max. O(n).
MediumdecodeLC 91 · Decode Waysdp[i] = dp[i-1] (single digit valid) + dp[i-2] (two digits valid). O(n).
MediumunboundedLC 322 · Coin Changedp[amount] = min coins. Unbounded knapsack variant. O(n·amount).
MediumproductLC 152 · Maximum Product SubarrayTrack max and min (negatives flip). O(n).
Mediumword-breakLC 139 · Word Breakdp[i] = can s[0..i] be segmented? Try all prefixes in dictionary. O(n·m).
MediumLISLC 300 · Longest Increasing SubsequenceO(n²) DP or O(n log n) with patience sorting.
MediumpalindromeLC 647 · Palindromic SubstringsExpand around each center. O(n²).

← Back to all LeetCode categories