LeetCode ยท Greedy
Greedy Problem Set
Make the locally optimal choice at every step. Sort + single pass + a few variables = greedy. Prove correctness with the exchange argument.
Concept page: Greedy
| Difficulty | Pattern | Problem | Key Insight |
|---|---|---|---|
| Medium | reachability | LC 55 ยท Jump Game | Track farthest reachable index. O(n). |
| Medium | BFS-greedy | LC 45 ยท Jump Game II | BFS levels: track current range end and farthest. O(n). |
| Medium | subarray | LC 53 ยท Maximum Subarray | Kadane's algorithm: reset running sum when negative. O(n). |
| Medium | surplus | LC 134 ยท Gas Station | Running tank + total check. Reset on negative. O(n). |
| Hard | two-pass | LC 135 ยท Candy | Left-to-right and right-to-left passes enforce both neighbor constraints. O(n). |
| Medium | parentheses | LC 678 ยท Valid Parenthesis String | Track min and max open count. O(n). |
| Medium | partition | LC 763 ยท Partition Labels | Track last occurrence of each char. Extend partition greedily. O(n). |
| Medium | grouping | LC 846 ยท Hand of Straights | Sort + greedily form consecutive groups. O(n log n). |
| Medium | merge | LC 1899 ยท Merge Triplets to Form Target Triplet | Filter valid triplets, check if all target values are coverable. O(n). |