Priority Job Scheduler with Cooldowns
Updated
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.
Return the result of every GET operation in order.
Function
runPriorityScheduler(operations: String[]) → String[]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.
Example 2
operations = ["GET","ADD beta 7 1","ADD alpha 7 2","GET","GET","GET","GET"]return = ["NONE","alpha","beta","NONE","alpha"]The first call has no registered jobs. On the next call, alpha wins the priority tie lexicographically. It needs two intervening calls, while beta needs one after being selected. Both are cooling on the fourth overall GET, and alpha returns on the fifth.
Constraints
1 <= operations.length <= 100000- Every operation is exactly
GETor has the formADD id priority cooldown. - Each identifier contains
1through20lowercase English letters and is added exactly once. 0 <= priority <= 10^90 <= cooldown <= operations.length
More Google Onsite Interview questions
- 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
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
- Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
- Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Expiring Key SetAmazon · ONSITE INTERVIEW
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
Google interview experiences
- Google L4 SWE Phone Screen: 1 Experience
- Google ML Engineering Manager Onsite: 1 Experience
- Google Experienced SWE First Round and Onsite: 1 Experience
- Google AI Coding Interview and AI OA: 2 Experiences
- Google SWE Intern Interview Results Timeline: 13 Experiences
- Google L4 SWE Phone Screen and Kirkland Onsite: 1 Experience