DP Notes
The layman's way of analyzing the runtime of a memoized recursive function is :
How to think in iterative DP?
1. Define what dp[i][j] or dp[i] will represent in your problem.
2. Initialize the base cases of the dp array.
dp[i][j] = maximum value that can be obtained with a weight limit of j and first i items.
Base Cases: dp[0][j] where 0<=j<=MaxWeight
So, Maximum value that can be obtained by choosing the item at index 0 and weight can be 0 to maxWeight.dp[i][j] = Number of ways to make a sum of j using first i coins.
Base Cases: dp[0][j] where 0<=j<=sum
So, Number of ways to make a sum of j using only index 0 coins.Steps to write DP solution in interview
Last updated