Delayed Job Scheduler
Updated
Problem statement
Implement a delayed-job scheduler for a fixed list of operations. The arrays actions, jobIds, times and delays describe each operation at the same index. Process them from first to last. Start with no pending jobs. Each time in times is at least as large as the one before it.
For this exercise, assume exactly two operations:
SCHEDULEadds the given unique positive job ID with due timetimes[i] + delays[i]. Return an empty row for this operation.POLLreturns and removes every pending job whose due time is at mosttimes[i]. Return IDs ordered by due time, then by the earlierSCHEDULEoperation when due times tie. An empty poll returns an empty row.
Return one integer-array row per operation, including empty rows. A zero-delay job may be released by a later poll at the same clock, but never by a poll that occurred before its schedule. Jobs not reached by a poll remain pending and produce no extra output.
The finite operations, clock and tie rules are as stated. This exercise schedules and releases jobs; it does not execute job bodies or add dependencies, cancellation, priorities, recurrence or profit optimization.
Function
runJobScheduler(actions: String[], jobIds: int[], times: int[], delays: int[]) → int[][]Examples
Example 1
actions = ["SCHEDULE","SCHEDULE","POLL","POLL"]jobIds = [1,2,0,0]times = [0,1,2,5]delays = [5,1,0,0]return = [[],[],[2],[1]]Jobs release by due time rather than insertion.
Example 2
actions = ["SCHEDULE","SCHEDULE","POLL"]jobIds = [8,3,0]times = [0,5,10]delays = [10,5,0]return = [[],[],[8,3]]Equal due times keep insertion order not ID order.
Example 3
actions = []jobIds = []times = []delays = []return = []Empty operation batch.
Constraints
- The four arrays have equal length
0 <= n <= 128. - Every action is
"SCHEDULE"or"POLL". 0 <= times[i], delays[i] <= 10^6, and times never decrease.- Every scheduled ID is a distinct positive integer at most
10^9and is never reused. - For
POLL, the unused ID and delay fields are0.
More Walmart Labs Onsite Interview questions
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
- Implement a Min-Priority QueueAmazon · ONSITE INTERVIEW
- Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
- Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
- Order Matching EngineJane Street · ONSITE INTERVIEWJane Street interview questions
- Trip Booking with the Earliest Free DriverRippling · ONSITE INTERVIEWRippling interview questions
- Reusable Number AllocatorDropbox · ONSITE INTERVIEWDropbox interview questions