Many string questions compare two texts or cut one text into pieces, and both have the same shape: the answer for a prefix, or a pair of prefixes, depends on slightly shorter prefixes. Define cell[i][j] as the answer for the first i letters of one string and the first j letters of the other, write how a cell follows from its neighbors, and fill the table row by row.
For two strings, a matching pair of letters extends the diagonal cell, and a mismatch takes the better of skipping a letter from either string. For cutting one string, ok[end] or ways[end] looks back over every place the last piece could start. Counting problems add the ways from each option; optimization problems take the minimum or maximum.
Two habits save time in interviews. Say what one cell means in a sentence before you write code, and decide the base row: the empty prefix usually has exactly one way or a cost of zero. When each row needs only the previous row, keep two rows and the space drops from O(nm) to O(m).
A match extends the diagonal; a mismatch keeps the better neighbor.