The Maximum Number of Eaten Apples coding problem simulates daily apple eating. Each day i, you receive apples[i] apples that will expire after days[i] days from day i (i.e., they expire at day i + days[i] - 1). Each day you eat at most one apple, choosing the one expiring soonest to minimize waste. After n days, you may continue eating leftover apples. Maximize the total apples eaten.
Uber includes this problem to test priority queue (min-heap) usage with greedy scheduling. It combines the classic "earliest deadline first" (EDF) scheduling algorithm with the added complexity of continuing beyond the input period. Candidates who recognize this as an EDF problem and implement it with a min-heap demonstrate strong scheduling algorithm knowledge.
Greedy with min-heap (priority queue): Use a min-heap keyed by expiry date. Each day:
(expiry_day, count) to the heap if count > 0.After day n, continue until the heap is empty, incrementing day each iteration and repeating the process. Total complexity: O(n log n).
apples = [1, 2, 3, 5, 2], days = [3, 1, 1, 4, 2]
For the Array Heap Priority Queue Greedy interview pattern, "earliest deadline first" is a foundational scheduling greedy. Whenever you see "choose the item expiring soonest to maximize total items used," reach for a min-heap keyed by expiry. Practice identifying EDF scenarios — they appear in scheduling, task assignment, and resource allocation problems at Uber, Google, and Amazon.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Furthest Building You Can Reach | Medium | Solve | |
| Make the Prefix Sum Non-negative | Medium | Solve | |
| Maximal Score After Applying K Operations | Medium | Solve | |
| Maximum Average Pass Ratio | Medium | Solve | |
| Maximum Product After K Increments | Medium | Solve |