Greedy Algorithm Visualizers

16

Step through every Greedy Algorithm problem with animated runtime state, source highlighting, and curated test cases. Built for coding-interview prep and durable algorithmic intuition.

Assign Cookies
Sort greed factors and cookie sizes, then eagerly feed the least greedy child first.
Greedy (Two Pointers/Sorting)
Best Time to Buy and Sell Stock II
Harvest all positive uphill price differences between adjacent days.
Greedy (Peak/Valley)
Candy
Compute local optimums with sweeping left-to-right pass followed by right-to-left pass.
Greedy (Two Passes)
Candy — One Pass O(1) Space
Decompose ratings into ascending/descending mountain runs and sum arithmetic triangles, adjusting the shared peak.
Greedy (Mountain Decomposition)
Car Pooling
Process pick-ups and drop-offs as net capacity changes on a timeline array.
Greedy (Difference Array / Line Sweep)
Gas Station
If tank runs negative, reset the candidate starting station to the next index immediately.
Greedy (Running Balance / Cycle)
Hand of Straights
Build straights by sequentially satisfying combinations using a frequency map.
Greedy (Sequence Building)
Insert Interval
Linearly add non-overlapping prefix intervals, merge overlaps via min/max expansion, then add suffix.
Greedy (Interval Merging)
Jump Game
Track the max reachable index; return false immediately if moving past it.
Greedy (Reachability)
Jump Game II
Track the farthest choice possible within the current jump boundary.
Greedy (Jump Boundary)
Lemonade Change
Prioritize giving $10 bills as change before $5 bills to maximize flexibility.
Greedy (Change Making)
Merge Intervals
Sort by start time, then iteratively expand the boundary of the active trailing interval.
Greedy (Interval Overlaps)
Non-overlapping Intervals
Sort intervals by earliest end time to minimize conflicts and maximize schedule space.
Greedy (Earliest Deadline First)
Partition Labels
Find last occurrences of each character, extending partition boundary until index catches up.
Greedy (Sliding Window Boundary)
Task Scheduler
Calculate hypothetical idle periods based on the most frequent task, then fill gaps.
Greedy (Frequency Max)
Two City Scheduling
Calculate cost differences to greedily send the people generating maximum relative savings to City A.
Greedy (Sorting by Difference)