Dynamic Programming21 sections · 916 units
Open in Course

What's Next

Preview of 2D DP

You've learned 1D DP. define states, write transitions, and reduce space. These problems all had one-dimensional state: position in an array.

But some problems need more. What if you're comparing two strings? You need to track positions in both. That's 2D DP.

What if you have a grid and need to track row and column? Again, two dimensions.

In the next section, you'll see how the same patterns scale up. States become dp[i][j]dp[i][j] instead of dp[i]dp[i]. Transitions look at more neighbors. Space reduction gets trickier.

The good news: everything you learned still applies. 2D DP is just 1D DP, done twice.