PROBLEM SOLVING - GREEDY TRICKS
Greedy Manipulation Approaches
| # | Technique | Use Case | Approach | Complexity | Examples |
|---|---|---|---|---|---|
| 1 | Interval scheduling | Max non-overlapping activities | Sort by finish/end; pick compatible next | O(n log n) |
|
| 2 | Ratio sorting | Fractional knapsack | Sort value/weight descending; fill greedily | O(n log n) |
|
| 3 | Deadline + profit | Job sequencing | Sort profit desc; place in latest free slot | O(n²) or O(n log n) |
|
| 4 | Min-heap merge | Huffman / rope merge | Always combine two smallest costs | O(n log n) |
|
| 5 | Event sweep | Platform / resource count | Sort arrivals/departs; sweep counter | O(n log n) |
|
| 6 | Coin greedy | Change making | Take largest coin ≤ remainder (canonical systems) | O(n) |
|
| 7 | MST cut property | Minimum spanning tree | Add min edge crossing cut (Prim/Kruskal) | O(E log E) |
|
| 8 | Shortest path greedy | Non-negative weights | Dijkstra: pick min distance vertex | O((V+E) log V) |
|
| 9 | Two-pointer greedy | Sorted pairing | Sort both arrays; pair i with i | O(n log n) |
|
| 10 | Monotonic stack | Remove k digits / build min | Pop while top > current and k > 0 | O(n) |
|
| 11 | Farthest reach | Jump game | Track max index reachable in one pass | O(n) |
|
| 12 | Tank / deficit | Circular tour | Reset start when tank negative | O(n) |
|
| 13 | Post-process greedy | Stock profit | Sum positive adjacent price diffs | O(n) |
|
| 14 | Max-heap refuel | Fuel stops | Push fuels in range; pop max when stuck | O(n log n) |
|
| 15 | Frequency heap | String rearrange | Always place most frequent char if legal | O(n log k) |
|
Related Greedy Resources
Related Greedy Algorithm Resources