Skip to content

2-D Dynamic Programming

When the state needs two numbers — a position in a grid, or a position in each of two strings — the DP table becomes a rectangle. You fill it cell by cell, each cell from its neighbours that are already filled.

After this topic: You can define dp[i][j] in a sentence, fill the table in the right order, and trim it to one row when possible.

Do these first: Graphs, 1-D Dynamic Programming

0 of 11 solved0%

Step 1 · Read the lesson

2-D Dynamic Programming

Grids, two strings and ranges: when a subproblem needs two numbers, fill a table cell by cell.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Unique PathsMedium
  2. 2.Longest Common SubsequenceMedium
  3. 3.Best Time to Buy and Sell Stock with CooldownMedium
  4. 4.Coin Change IIMedium
  5. 5.Target SumMedium
  6. 6.Interleaving StringMedium
  7. 7.Longest Increasing Path in a MatrixHard
  8. 8.Distinct SubsequencesHard
  9. 9.Edit DistanceMedium
  10. 10.Burst BalloonsHard
  11. 11.Regular Expression MatchingHard

Step 3 · What this unlocks