FastPrepAd Rotation Scheduler With Cooldown
Problems/Ad Rotation Scheduler With Cooldown

Ad Rotation Scheduler With Cooldown

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Backed by a real Google onsite interview report. Estimated match rate: 85-90% for the core scheduling task. The original report shared the ad rotation idea and the cooldown follow-up, but did not specify the exact class signature, what to return when no ad is available, whether ad IDs are 0-based or 1-based, or whether cooldown is measured by calls or wall-clock time. FastPrep uses a deterministic iterator-style interface, 1-based ad IDs, a per-ad cooldowns array, -1 when no ad can be shown, and cooldown measured in number of next() calls. The original poster said the interview was completed in the first half of 2026, but did not share the exact interview date. I saw the report on 2026-07-09, so FastPrep uses that date as the last-seen date.

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.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Combine the Two Smallest Until All Reach kAdobe · PHONE SCREENAdobe interview questions
  • API Call Thread Pool ScheduleBaseten · ONSITE INTERVIEWBaseten interview questions
  • Streaming Ingredient DishesHarness · ONSITE INTERVIEW
  • CPU Scheduling SimulatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Assign Partitions to the Least-Loaded ServersAmazon · ONSITE INTERVIEW
  • Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Dynamic Batch Decode TracexAI · ONSITE INTERVIEWxAI interview questions
  • Team-Preferred Stable MatchingBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Batch API Requests with Retry DelaysDecagon · PHONE SCREENDecagon interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] scheduleAdsWithCooldown(int[] counts, int[] cooldowns) {
      // write your code here
    }

}
Checking account…