LeetCode · DP — 2D

Dynamic Programming — 2D Problem Set

Two-dimensional DP tables, string matching, grid traversal, and advanced state transitions. The hardest DP problems live here.

Concept page: Dynamic Programming
DifficultyPatternProblemKey Insight
MediumgridLC 62 · Unique Pathsdp[i][j] = dp[i-1][j] + dp[i][j-1]. O(m·n).
MediumstringLC 5 · Longest Palindromic SubstringExpand around center or 2D DP. O(n²).
MediumLCSLC 1143 · Longest Common SubsequenceClassic 2D DP: match → dp[i-1][j-1]+1, else max(left, top). O(m·n).
MediumknapsackLC 494 · Target SumSubset sum variant with offset. O(n·sum).
MediumunboundedLC 518 · Coin Change IICount combinations (not permutations). 2D or 1D space-optimised. O(n·amount).
Mediumstate-machineLC 309 · Best Time to Buy and Sell Stock with CooldownThree states: hold, sold, rest. O(n).
MediuminterleaveLC 97 · Interleaving Stringdp[i][j] = can s1[0..i] + s2[0..j] form s3[0..i+j]? O(m·n).
HardeditLC 72 · Edit DistanceInsert, delete, or replace. dp[i][j] = min operations. O(m·n).
HardregexLC 10 · Regular Expression Matching2D DP handling '.' and '*'. O(m·n).

← Back to all LeetCode categories