π― 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 16 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β
Array of Doubled Pairs
LeetCode 991 | Difficulty: Medium
Can Place Flowers
LeetCode 605 | Difficulty: Easy
Destroying Asteroids
LeetCode 2245 | Difficulty: Medium
Find Original Array From Doubled Array
LeetCode 2117 | 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
Minimum Adjacent Swaps for K Consecutive Ones
LeetCode 1805 | Difficulty: Hard
Minimum Deletions to Make Character Frequencies Unique
LeetCode 1770 | Difficulty: Medium
Minimum Time to Make Rope Colorful
LeetCode 1700 | Difficulty: Medium
Remove K Digits
LeetCode 402 | Difficulty: Medium
Removing Minimum Number of Magic Beans
LeetCode 2290 | Difficulty: Medium
Task Scheduler
LeetCode 621 | Difficulty: Medium
Teemo Attacking
LeetCode 495 | Difficulty: Easy
Video Stitching
LeetCode 1081 | Difficulty: Medium