Back to all patterns

Dynamic Programming (2D)

6 problems • Practice on LeetCode to earn credits

About This Pattern

Master the Dynamic Programming (2D) pattern by practicing these problems organized by difficulty.Focus on the Key Signals - these are the indicators that tell you when to use this pattern.

Medium (3)

Unique Paths

Count unique paths from top-left to bottom-right in a grid (only right/down moves).

Key Signals:

Grid DPdp[i][j] = dp[i-1][j] + dp[i][j-1]Count paths
Longest Common Subsequence

Find length of longest common subsequence between two strings.

Key Signals:

Match or skipdp[i][j] based on matchClassic 2D DP
Interleaving String

Check if s3 is formed by interleaving s1 and s2.

Key Signals:

Two strings to one2D grid of choicesMatch characters from s1 or s2

Hard (3)

Distinct Subsequences

Count distinct subsequences of s that equal t.

Key Signals:

Match or skipCount ways2D DP table
Edit Distance

Find minimum edit distance (insert, delete, replace) between two strings.

Key Signals:

Three operationsMin of three choicesClassic edit distance
Regular Expression Matching

Implement regular expression matching with '.' and '*'.

Key Signals:

Handle . and * patternsMatch or star logicComplex state transitions