Ad Rotation Scheduler With Cooldown
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's July 2026 report of the ad rotation scheduler with cooldown comes down to one data structure: a queue. If you've got an OA coming up, expect a simulation where ads cycle in round-robin order and some of them are temporarily benched. The twist is that cooldown is counted in calls to next(), not wall time, and empty calls still burn a tick. Candidates who treat it as a plain cycle get examples 1 and 2 right and fall apart on example 3. It's a clean problem once you see the two holding areas. StealthCoder is the safety net if your mind goes blank mid-assessment.
The problem
You are building an ad rotation scheduler. There are n ads, numbered from 1 to n. Ad i must be shown exactly counts[i - 1] times. Implement the scheduler by returning the sequence of values that repeated calls to next() would produce. On each call, the scheduler should choose the next currently available ad in round-robin order. Initially, available ads are ordered by increasing ad ID. After an ad is shown, if it still has remaining displays, it becomes unavailable for its cooldown period and then returns to the back of the available queue. Cooldown is measured in calls to next(). If ad i is shown on call t, it can be shown again no earlier than call t + cooldowns[i - 1] + 1. If no ad is available on a call but some displays remain, that call returns -1 and time still advances by one call. Return the full output sequence until all display counts have been consumed. Do not include trailing -1 values after every ad has been shown the required number of times. Original Interview Report Onsite 2 was an ad rotation / scheduling problem. Multiple ads each have a display count. Design next(); each call returns the next ad, rotating through ads as evenly as possible, such as 1,2,3,1,2,3, unless only one ad remains. The follow-up adds cooldown: after an ad is displayed, it must wait for its corresponding cooldown period before it can be displayed again. Function scheduleAdsWithCooldown(counts: int[], cooldowns: int[]) → int[] Examples Example 1 counts = [2,2,2] cooldowns = [0,0,0] return = [1,2,3,1,2,3] All ads have no cooldown, so the scheduler cycles through them in round-robin order. Example 2 counts = [3,1] cooldowns = [0,0] return = [1,2,1,1] After ad 2 has been used once, only ad 1 remains, so it is returned on the remaining calls. Example 3 counts = [3] cooldowns = [2] return = [1,-1,-1,1,-1,-1,1] The only ad must wait two calls after each display. During those waiting calls, no ad is available, so -1 is returned. Constraints 1 <= counts.length == cooldowns.length <= 2000 0 <= counts[i] <= 2000 for at least one ad 0 <= cooldowns[i] <= 2000 The returned sequence length will not exceed 200,000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a queue of available ad IDs, initially 1 to n, skipping ads with zero count. Also keep a cooldown holding area, either a min-heap or a map keyed by the call number when the ad returns. At each time t, first move any ads whose return time is t into the back of the available queue. Then pop the front, record it, decrement its count, and if it still has displays left, schedule its return at t + cooldowns[i-1] + 1. If the queue is empty but displays remain, append -1. Stop the moment every count hits zero, so no trailing -1s. The common pitfall is the order of operations: release returning ads before popping, and keep release order stable if several return on the same call. Off-by-one on the cooldown is the other trap. Example 3 is your test. StealthCoder is the hedge if you freeze on the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Ad Rotation Scheduler With Cooldown 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Ad Rotation Scheduler With Cooldown FAQ
What's the trick in the Google ad rotation scheduler problem?+
Use two structures. A queue holds ads ready to show, and a holding area (heap or map by return time) holds ads on cooldown. Each tick, release returning ads to the back of the queue, then pop the front. It's a plain simulation, not anything clever.
How do I get the cooldown off-by-one right?+
If an ad shows on call t, it can show again at call t + cooldowns[i-1] + 1. Store that value as its return time and release it at the start of that call. Test with counts=[3], cooldowns=[2]. You should get 1,-1,-1,1,-1,-1,1.
When do I output -1 and when do I stop?+
Output -1 when the available queue is empty but some ad still has displays left. Time still advances. Stop right after the last display is consumed, so the output never ends with extra -1 values.
What's the time complexity?+
Each output call does constant queue work, plus heap work if you use a heap for cooldowns. The output is capped at 200,000, so even a log factor is fine. Simulating tick by tick is well within the constraints, no need to optimize further.
How should I prepare for this in 48 hours?+
Hand-trace the three examples until the order of release then pop is automatic. Then code it once from scratch with a deque and a min-heap. Check edge cases: ads with zero count, one ad left, and several ads returning on the same call.