Problem · Heap

Priority Job Scheduler with Cooldowns

MediumGoogle logoGoogleFULLTIMEONSITE INTERVIEW
See Google hiring insights

Problem statement

Simulate a scheduler over the finite sequence in operations. Each operation is one of:

  • ADD id priority cooldown: register one persistent job with a unique lowercase identifier, integer priority, and nonnegative cooldown.
  • GET: return the eligible job with the greatest priority. If several eligible jobs have the same priority, return the lexicographically smallest identifier. If no job is eligible, return NONE.

Only GET operations advance scheduler time. A newly added job is eligible immediately. After a job is returned by a GET, it remains registered but is ineligible for its next cooldown intervening GET operations. For example, if a job with cooldown 3 is returned on one call, three later GET calls must occur before it can be returned again. A GET that returns NONE still counts as an intervening call.

The problem statement continues
Pro

Examples

Example 1

operations = ["ADD A 10 3","ADD B 5 0","GET","GET","GET","GET","GET"]return = ["A","B","B","B","A"]

Job A wins the first call by priority. Its cooldown requires calls two, three, and four to intervene, so A becomes eligible again on call five. Job B has cooldown 0 and fills the intervening calls.

FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week