A couple of quick notes before summarizing some common Dynamic Programming Patterns, how to recognize them and how their recurrence relations work:
- Do not memorize patterns to get good at DP. Have them as reference points in your head in case your stuck.
- Always think of DP as an afterthought after thinking how a problem can be solved recursively (i.e. think of the "Optimal Substructure" property first and then use DP to reduce redundant work from the "Overlapping Subproblems")
- The intuition for DP comes from the Top-Down appraoch of thinking of it (i.e. the "Optimal Substructure) - Bottom Up approaches are optimizations. You should explain your solution with Top-Down logic, even if you want to eventually optimize with Bottom-Up.
When explaining DP solutions:
- Use appropriate terminology - refering to states, transitions, recurrence relations etc. will make it a lot easier for interviewers to follow your reasoning.
- Clearly state your recurrence relation / lo