Greedy: when to spot it, explain it, and practice it
Greedy is not a pattern you recognize from syntax. You recognize it when one local choice can be proven safe because any better global solution can be transformed to match it without getting worse.
Pattern coverage
45+
Best first move
Name the greedy choice explicitly.
Common failure point
Choosing greedily without any argument against counterexamples.
When this pattern should come to mind
Checklist before you code
The solving flow that works well in interviews
Identify the local choice that seems to preserve the most future flexibility.
Sort or preprocess if that makes the choice testable.
State the invariant after taking that greedy action.
Use a proof sketch or exchange argument to justify it.
Only then implement the linear scan or boundary tracking.
Common variants
Interval scheduling
Sort by end time or start time based on what keeps future choices widest.
Reachability greedy
Track the best boundary or farthest reach so far.
Resource allocation
Pick the choice that minimizes future cost or overlap.
Template preview
items.sort(key=priority)
answer = 0
for item in items:
if can_take(item):
take(item)
answer = update(answer)
Classic problems with useful framing
#45
Jump Game II
Shows how greedy can optimize layer-by-layer reach.
Find the minimum number of jumps to reach the last index.
#56
Merge Intervals
A gentle transition from sorting to greedy merging.
Merge all overlapping intervals.
#435
Non-overlapping Intervals
Classic end-time greedy proof problem.
Remove the minimum number of intervals to eliminate overlaps.
#452
Minimum Number of Arrows to Burst Balloons
Great for overlap reasoning after sorting.
Use the minimum arrows to burst all balloon intervals.
A more useful problem ladder for practice
This is not a random list. It is ordered to help candidates build recognition first, add key variants next, and then increase pressure with harder cases.
Foundation
#45 Jump Game II
Find the minimum number of jumps to reach the last index.
You only increment the jump count when the current layer ends, not every time you see a farther reach.
Foundation
#55 Jump Game
Decide whether you can reach the last index.
As long as your index stays within the current farthest reach, you can extend that reach using nums[i].
Variant depth
#56 Merge Intervals
Merge all overlapping intervals.
Once intervals are sorted by start, overlap decisions only depend on the current merged interval's end.
Variant depth
#435 Non-overlapping Intervals
Remove the minimum number of intervals to eliminate overlaps.
When intervals overlap, the later-ending one is the worse candidate to keep.
Pressure test
#452 Minimum Number of Arrows to Burst Balloons
Use the minimum arrows to burst all balloon intervals.
If two balloons overlap, one arrow at the common overlap can handle both, so only the overlap boundary matters.
High-frequency mistakes
Choosing greedily without any argument against counterexamples.
Sorting by a key that feels plausible but is not part of a proof.
Mistaking a monotonic boundary problem for DP or vice versa.
Only explaining implementation and never explaining why greedy works.
Recommended practice path
Start with jump game and interval merge/removal.
Then solve arrow shooting and queue reconstruction.
Add partition or token-budget style greedy problems next.
Finish with harder proof-heavy greedy questions after the intuition settles.