Skip to main content

🎯 Greedy

Greedy is "take the best local choice and hope it stays optimal". When it works it is the simplest solution; when it does not, you need DP. Always prove it works β€” counterexample first.

This category contains 9 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • Interval Scheduling β€” Sort by end time, take earliest-finishing.
  • Activity Selection β€” Maximize non-overlapping count.
  • Jump Game β€” Track furthest reachable index as you scan.
  • Huffman-like β€” Repeatedly merge two smallest (heap).
  • Exchange Argument Proofs β€” Show swapping any pair never improves the greedy choice.

⚠️ Common Pitfalls​

  • Assuming greedy works without proof β€” many problems look greedy but need DP (coin change with arbitrary denominations).
  • Sorting key matters: by start vs by end can give very different results.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

  • Algorithm Design β€” Kleinberg & Tardos β€” Ch. 4 β€” best treatment of greedy proofs anywhere
  • Introduction to Algorithms (CLRS) β€” Ch. 16

🌐 Articles & References​


πŸ’» All Greedy Problems​