π― 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β
Destroying Asteroids
LeetCode 2245 | Difficulty: Medium
Jump Game
LeetCode 55 | Difficulty: Medium
Jump Game II
LeetCode 45 | Difficulty: Medium
Jump Game III
LeetCode 1428 | Difficulty: Medium
Maximum Units on a Truck
LeetCode 1829 | Difficulty: Easy
Remove K Digits
LeetCode 402 | Difficulty: Medium
Task Scheduler
LeetCode 621 | Difficulty: Medium
Teemo Attacking
LeetCode 495 | Difficulty: Easy
Video Stitching
LeetCode 1081 | Difficulty: Medium