r/codinginterview • u/jaspindersingh83 • May 15 '20
DP == Optimization of repeated sub problems.
How to identify every DP problem.
Check if greedy (Choosing an optimal decision at every step) works for the problems. If not
Draw the recursive brute force solution of a problem and Identify the repeated sub problem.
Decide whether to use a 1D array or a 2D to memoize the repeated sub problems results.
Every DP problem can be identified using above cardinal rules. DP problems are easiest to decipher.
2
Upvotes
2
u/bparanj May 15 '20
Here is my notes from MIT course video:
5 Easy Steps to DP
Define subproblems
Guess (part of the solution)
Relate subproblem solutions
Recurse and memoize or build DP table bottom-up
Solve original problem.