Dynamic Programming (DP) is an optimization technique used to solve complex problems by breaking them into smaller overlapping subproblems, solving each subproblem only once, and storing the results to avoid redundant calculations. It is mainly applied to optimization problems where we need to find the minimum, maximum, shortest, or longest solution. https://www.enjoyalgorithms.com/blog/introduction-to-dynamic-programming
- Break the problem into smaller subproblems (like divide-and-conquer).
- Find the optimal solution for each subproblem.
- Store results of subproblems (memoization) to avoid recomputation.
- Reuse stored results to efficiently compute the final solution.
- Top-Down (Memoization) β Uses recursion with caching to store intermediate results.
- Bottom-Up (Tabulation) β Uses an iterative approach to build solutions from smaller subproblems.
Find out the nth Fibonacci number. Fibonacci number of a position is equal to the summation of the previous two numbers Fibonacci. So Fibonacci of fib(n) is fib(n-1) + fib(n-1).
Fibonacci of 6 is:

Here we divide the problem into several subproblems and conquer the result of the subproblems and finally get the optimal solution. But there is a problem that is here we are calculating a subproblem more than once. Here we calculate fib(4) twice, fib(3) three-time, fib(2) five times, fib(1) three times. Instead of calculating more than once we will store the solution of the subproblem and will use it for the next time.
- DP finds all possible solutions and picks the optimal one.
- Greedy makes local optimal choices but doesnβt always guarantee the global optimum.
- DP is time-consuming compared to greedy algorithms but guarantees the optimal solution if it exists.
| Difficulty | Problem | Type | Link | Company |
|---|---|---|---|---|
| Easy | Climbing Stairs | CW | π Link | Adobe |
| Easy | Best Time to Buy and Sell a Stock | CW | π Link | Adobe |
| Easy | Maximum Subarray | CW | π Link | Uber |
| Easy | House Robber | HW | π Link | Amazon |
##Dynamic Programming (Intermediate Problems)
| Difficulty | Problem | Type | Link | Company |
|---|---|---|---|---|
| Medium | Jump Game | HW | π Link | |
| Medium | Unique Paths | CW | π Link | Netflix |
| Medium | Coin Change | CW | π Link | Netflix |
| Medium | Longest Increasing Subsequence | CW | π Link | Apple |
| Difficulty | Problem | Type | Link | Company |
|---|---|---|---|---|
| Hard | Maximum Product Subarray | HW | π Link | Adobe |
| Hard | Decode Ways | CW | π Link | Netflix |
| Hard | Best Time to Buy and Sell a Stock with Cooldown | CW | π Link |
| Difficulty | Problem | Type | Link | Company |
|---|---|---|---|---|
| Hard | Perfect Squares | HW | π Link | Amazon |
| Hard | Word Break | CW | π Link | Adobe |
| Hard | Word Break 2 | CW | π Link | Adobe |
- CW: Classwork
- HW: Homework