Skip to content
advanced

Two-Dimensional Dynamic Programming

Model DP problems that naturally require two coordinates or progress dimensions.

Problems

Problems in Two-Dimensional Dynamic Programming

Practice problems that share this primary solution pattern and compare the clues that reveal it.

Scenic view of an ancient Roman aqueduct in Tuscany, showcasing historic architecture.
expert
14 min read

Regular Expression Matching

A greedy scan breaks at * because the pattern can take two legal futures: skip the quantified element, or consume one matching character and keep the same…

View solution
Close-up of colorful yarn balls with onion dye in a rustic basket, highlighting natural dyeing techniques.
advanced
13 min read

Edit Distance

The table is easy to memorize and easy to misuse. The durable idea is simpler: track how far you have consumed each string, then let the final operation…

View solution
Intricate network of tangled power and communication cables outdoors.
advanced
12 min read

Interleaving String

When both source strings can provide the next target character, a greedy pointer has to guess. Dynamic programming keeps both possibilities alive until the…

View solution
Detailed view of an Opt Lasers engraving machine in operation, showcasing precision technology.
intermediate
11 min read

Minimum Path Sum

The right Minimum Path Sum solution is a two-dimensional dynamic program. For every coordinate, store the minimum sum needed to reach it from the top-left.…

View solution
Aerial view of Göbeklitepe archaeological site in Şanlıurfa, Türkiye, showcasing ancient stone structures.
expert
13 min read

Scramble String

The difficult part of the Scramble String solution is not recognizing that characters are rearranged. It is preserving the recursive boundaries that made…

View solution
Crop unrecognizable female student doing Internet research on laptop while sitting on cozy blanket in green summer park on sunny day
intermediate
10 min read

Unique Paths

The reliable way to solve Unique Paths is to count paths to each cell, not to enumerate complete routes. Every cell has at most two meaningful…

View solution
A cardboard robot figurine standing amid lush green grass outdoors during the day.
intermediate
12 min read

Unique Paths II

The recurrence is familiar. The interview usually turns on the cells you forgot: a blocked start, a blocked destination, or an obstacle that permanently…

View solution
Networking equipment with connected cables, showcasing modern technology infrastructure.
expert
13 min read

Wildcard Matching

The reliable way to solve wildcard matching is to model it as reachability over two consumed prefixes—not as an improvised backtracking fight with *.

View solution