Edit Distance
Recognize the pattern
Brute force idea
A straightforward first read of Edit Distance is this: Try all possible sequences of operations recursively. Three choices at each mismatch, leading to exponential branching. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The deeper shift in Edit Distance is this: 2D DP: dp[i][j] = min operations to convert word1[0.i-1] to word2[0.j-1]. If characters match, dp[i][j] = dp[i-1][j-1]. Otherwise, min of insert (dp[i][j-1]+1), delete (dp[i-1][j]+1), replace (dp[i-1][j-1]+1). Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
Key invariant
At the center of Edit Distance is one steady idea: dp[i][j] represents the exact minimum cost to align the first i characters of word1 with the first j characters of word2. Each cell depends only on three neighbors — left, above, and diagonal. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
One easy way to drift off course in Edit Distance is this: Confusing which operation maps to which cell transition. Insert = move right (dp[i][j-1]), delete = move down (dp[i-1][j]), replace = move diagonally (dp[i-1][j-1]). The fix is usually to return to the meaning of each move, not just the steps themselves.