The coin-change lesson filled a table with one index, the amount. Most dynamic programs in interviews need more than one number to say where you are:
a position in a list, and how many deletions you've used
a spot in each of two strings
a junction on a trail, and how many expert stretches you've ridden to get there
This lesson is about those states with more than one part, and the tables they fill.
Collect points from the top-left to the bottom-right
grid
314115926535
Start at the green 3 and end at the green 5, moving only right or down.
You start at the top-left cell and move only right or down. You collect the points of every cell you pass. What's the most you can collect by the bottom-right cell?
Predict
Moving only right or down, what's the most you can collect by the bottom-right cell?
Before any code, write down four things. In an interview, say them out loud.
What one cell means, in words.best[r][c] is the most points on any path from the top-left cell to cell (r, c), that cell's own points included. The state has two parts, the row and the column, so the table has two dimensions.
The recurrence, the rule that builds a cell from other cells. The last step into (r, c) came from above or from the left, so best[r][c] = grid[r][c] + max(best[r - 1][c], best[r][c - 1]).
The base cases, the cells that have nothing to read. best[0][0] = grid[0][0]. A cell in the top row has nothing above it, and a cell in the left column has nothing to its left. A missing neighbor counts as minus infinity, so the max never picks it.
An order in which every cell's inputs are ready before it. Row by row from the top, left to right in each row. The cell above and the cell to the left are both filled before the cell itself.