Priority Job Scheduler with Cooldowns
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, returnNONE.
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.
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.
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
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.