Task Scheduler
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's Task Scheduler question hit the OA circuit hard in October 2024, and it's a classic greedy-simulation hybrid that trips up candidates who overthink the queue mechanics. You're given tasks with cooldown periods, and the problem asks for the minimum time to complete all of them. The trick isn't complex data structures; it's understanding how idle time gets scheduled. If you blank on the interval logic during the live OA, StealthCoder will catch the pattern and feed you the right approach in real time.
Pattern and pitfall
The core pattern is greedy simulation with a queue. You track task frequencies, schedule the most frequent tasks first (to spread out the cooldown impact), and fill gaps with either other tasks or idle time. The key insight: if you have a task with frequency F, it needs at least (F-1) * (cooldown + 1) + 1 total time slots. Many candidates get lost in the queue implementation or try to over-optimize with heaps. The real trick is recognizing that you either fill cooldown windows with other tasks or insert idle blocks, and the math solves itself. During the OA, if you can't recall the exact interval formula, StealthCoder serves as your safety net to unblock and move forward.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Task Scheduler cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as task scheduler. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Task Scheduler FAQ
Is this just a priority queue problem?+
Partially. You do use a max heap to prioritize high-frequency tasks, but the greedy part is the real challenge. The queue tells you which task to pick next; the math tells you if you need idle time. Don't get trapped in heap minutiae.
What's the most common mistake?+
Forgetting that idle time counts as actual time units. Candidates often calculate task frequency but skip the idle slots needed between repeated tasks. The formula (max_frequency - 1) * (cooldown + 1) + 1 is your safety net.
Do I need to simulate every time unit?+
No. That's the trap. You can jump directly to the answer using the frequency formula and then check if other tasks can fill the gaps. Simulating every tick is slow and error-prone.
How hard is Amazon's version compared to LeetCode 621?+
It's the same problem or a direct clone. If you've done LeetCode 621, you've already seen the solution. If not, study that problem's approach: heap, frequency, cooldown math, and edge case handling for when other tasks fill all idle windows.
Can I solve this in 24 hours if I'm seeing it fresh?+
Yes, but only if you focus on the pattern, not the code. Understand why the math works (spreading tasks to avoid repeated execution within cooldown), write the heap logic, and handle the idle time calculation. Spend 20 minutes on the idea, 40 on the code.