OCEAN
Dsa

Dynamic Programming and Greedy

A practical guide to DP and greedy interview patterns, including Fibonacci, knapsack, LIS, LCS, grid DP, tree DP, interval scheduling, and jump game

Why DP and Greedy Are Often Confused

Both dynamic programming and greedy try to make optimal decisions, but they do it differently:

  • greedy makes the best-looking local choice and never looks back
  • DP explores all important states, stores them, and builds the global answer

A good interview skill is knowing when local choice is enough and when you must preserve state.


Algorithms in This Topic

On this page