P07 — Dynamic programming — every solution explained
This lesson is part of full access
One payment of ₹250 opens every lesson, practice set and mock for all five companies. No subscription, no expiry.
What is inside
- 1. Ways to climb n stairs taking 1 or 2 steps
- 2. DECODE WAYS -- the dated question. 'A'=1 ... 'Z'=26. dp[i] = the number of ways to decode the FIRST i characters
- 3. The same thing as plain recursion -- exponential, but it SCORES on small inputs. Write this if the recurrence will not come to you
- 4. Fibonacci, bottom-up. The shape every 1-D DP reduces to
- 5. Cheapest way to the top when each step charges a toll
- 6. Largest total from non-adjacent elements
- 7. Largest sum of any contiguous subarray (Kadane)
- 8. Largest product of any contiguous subarray. Track BOTH ends -- a negative flips them
- 9. Fewest coins summing to amount; -1 if impossible
- 10. How many distinct COMBINATIONS of coins sum to amount. Coin loop outside, amount inside -- swap them and you count permutations instead
- 11. Length of the longest strictly increasing subsequence. O(n^2) is fine here
- 12. Can the array be split into two parts with equal sums? Subset sum over one dimension
- 13. Ways to reach step n taking 1, 2 or 3 steps