FastPrepAd Score Scheduler With Delay
Problems/Ad Score Scheduler With Delay

Ad Score Scheduler With Delay

Google logoGoogle● MediumFULLTIMENEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice version is about a 92% match to the available interview report. Inserting scored advertisements, returning the highest-scored eligible ad, decrementing its score, preventing consecutive repeats, and the per-ad delay follow-up come directly from the report. The operation-list wrapper, tie-breaking rule, empty-result value, identifier format, and numeric limits were not shown, so those execution details are defined below.

Process the operations in operations against an advertisement scheduler. Each operation is one of:

  • INSERT id score delay: insert a new advertisement with a unique identifier, its current integer score, and a nonnegative delay.
  • GET: return the eligible advertisement with the highest current score. If several eligible ads have the same score, return the lexicographically smallest identifier. After an ad is returned, decrease its score by 1.

An advertisement returned by a GET cannot be returned on the next max(1, delay) GET calls. This guarantees that the same advertisement is never returned consecutively, even when its declared delay is 0. Calls that return no ad still count toward every waiting period.

If no advertisement is eligible, return NONE. Inserted advertisements remain registered for the rest of the simulation. Return the result of every GET operation in order.

Function

runAdScheduler(operations: String[]) → String[]

Examples

Example 1

operations = ["INSERT alpha 5 0","INSERT beta 4 0","GET","GET","GET"]return = ["alpha","beta","alpha"]

alpha wins the first call and its score becomes 4. It cannot repeat immediately, so beta is returned next. On the third call, alpha is eligible again and has the larger score.

Example 2

operations = ["INSERT a 10 2","INSERT b 5 0","GET","GET","GET","GET"]return = ["a","b","NONE","a"]

After the first result, a must sit out two calls. After the second result, b must sit out one call, so the third call has no eligible ad. Both are eligible by the fourth call, and a has the larger score.

Constraints

  • 1 <= operations.length <= 100000
  • Every operation is exactly GET or has the form INSERT id score delay.
  • Each identifier contains 1 through 20 lowercase English letters and is inserted exactly once.
  • -1000000000 <= score <= 1000000000
  • 0 <= delay <= operations.length

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] runAdScheduler(String[] operations) {
      // write your code here
    }

}
Checking account…