FastPrepNamed Async Task Scheduler
Problems/Named Async Task Scheduler

Named Async Task Scheduler

Airwallex logoAirwallex● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report gives these rules: tasks with the same name run one after another, tasks with different names run at the same time, cancelling a task moves the same-name queue forward, and one call clears every task for a name. It leaves out timing, the order for ties, a function signature, how to write the output, and the constraints. We keep the reported state changes by running everything in virtual time with a list of operations.

Our version is about 90% the same as the reported question.

Simulate a scheduler that runs tasks asynchronously, so several tasks can be running at once. Process operations in order, and keep a virtual clock that starts at 0.

Operations

  • ["ADD", name, taskId, duration]: add a task. Its duration is a positive integer. If no task with that name is running, start it now. Otherwise, put it at the back of that name's FIFO queue. FIFO means first in, first out: queued tasks leave in the order they joined.
  • ["ADVANCE", delta]: move the clock forward by delta, a nonnegative integer. The new time is the target time. Handle every task that finishes at or before the target time.
  • ["CANCEL", name]: cancel the task with that name that is running now. If there is one, start the next queued task with the same name right away. The rest of the queue stays.
  • ["CLEAR", name]: remove the running task and every queued task with that name. Tasks with other names are never affected.

Two tasks with the same name never run at the same time. Tasks with different names may run at the same time.

Completion ordering

A queued task starts at the exact time the task before it finishes or is cancelled. During ADVANCE, handle finishing tasks by earlier finish time first. If two tasks finish at the same time, handle first the one whose name is lexicographically smaller (string order: compare the names character by character using character codes, and a name that is the beginning of a longer name comes first). For each finishing task, record its FINISH event, then start the next task with that name before you handle the next finishing task. Durations are positive, so a task that just started cannot finish at that same moment.

After handling those tasks, set the clock to the target time. A task that finishes exactly at the target time completes before the next operation. When the operations run out, stop: tasks that have not finished are not run to the end.

Return value

Return every task event, in the order the events happen, using exactly these forms:

  • time:START:name:taskId
  • time:QUEUE:name:taskId
  • time:FINISH:name:taskId
  • time:CANCEL:name:taskId, or time:CANCEL_NONE:name
  • time:CLEAR:name:taskId for the running task first and then queued tasks in FIFO order, or time:CLEAR_NONE:name

Function

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

Examples

Example 1

operations = [["ADD","alpha","a1","5"],["ADD","alpha","a2","2"],["ADD","beta","b1","3"],["ADVANCE","3"],["ADVANCE","2"],["ADVANCE","2"]]return = ["0:START:alpha:a1","0:QUEUE:alpha:a2","0:START:beta:b1","3:FINISH:beta:b1","5:FINISH:alpha:a1","5:START:alpha:a2","7:FINISH:alpha:a2"]

The names alpha and beta are different, so a1 and b1 run at the same time. The second alpha task, a2, waits in the queue until a1 finishes. Meanwhile, b1 finishes on its own at time 3.

Example 2

operations = [["ADD","sync","s1","10"],["ADD","sync","s2","4"],["ADD","sync","s3","1"],["ADVANCE","3"],["CANCEL","sync"],["ADVANCE","4"],["ADVANCE","1"]]return = ["0:START:sync:s1","0:QUEUE:sync:s2","0:QUEUE:sync:s3","3:CANCEL:sync:s1","3:START:sync:s2","7:FINISH:sync:s2","7:START:sync:s3","8:FINISH:sync:s3"]

Cancelling s1 at time 3 starts the next queued sync task, s2, right away. Task s1 would have finished at time 10, but it was cancelled, so no FINISH event for it ever appears.

Example 3

operations = [["ADD","red","r1","8"],["ADD","red","r2","2"],["ADD","blue","b1","4"],["ADVANCE","2"],["CLEAR","red"],["ADVANCE","2"],["CANCEL","red"],["CLEAR","red"]]return = ["0:START:red:r1","0:QUEUE:red:r2","0:START:blue:b1","2:CLEAR:red:r1","2:CLEAR:red:r2","4:FINISH:blue:b1","4:CANCEL_NONE:red","4:CLEAR_NONE:red"]

Clearing red removes its running task r1 first and then its queued task r2. The blue task keeps running and finishes later. After that, no red task is left, so the cancel and the second clear give CANCEL_NONE and CLEAR_NONE.

Constraints

  • 0 <= operations.length <= 100000.
  • Every row has one of the four exact forms above.
  • name and taskId contain 1 to 20 lowercase ASCII letters, digits, or underscores, and do not contain colons.
  • Every taskId in an ADD operation is globally unique.
  • 1 <= duration <= 10^9 and 0 <= delta <= 10^9.
  • The virtual clock never exceeds 10^14.
  • The returned array contains at most 200000 events.

More Airwallex interview questions

  • 4Sum Index QuadruplesPHONE SCREEN · Seen Sep 2026
  • Paginated K-Way Unique MergePHONE SCREEN · Seen Sep 2026
  • Largest Rectangle in HistogramPHONE SCREEN · Seen Aug 2026
  • Maximal SquarePHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Ad Score Scheduler With DelayGoogle · ONSITE INTERVIEWGoogle interview questions
  • Progressive Banking SystemAirbnb · OAAirbnb interview questions
  • Split Tender Part 4 - RefundsStripe · OA · PHONE SCREENStripe interview questions
  • Cloud Compute Credits SystemCoinbase · OACoinbase interview questions
  • Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
  • Weighted LFU CacheIMC Trading · OAIMC Trading interview questions
  • Get Priorities after Execution 🥭Amazon · OA
  • Organization Reputation After Employee DeparturesHSBC · OAHSBC interview questions
All Airwallex interview questionsSee Airwallex hiring insights
Saved
class Solution {
    public String[] runNamedTaskScheduler(String[][] operations) {
        // Write your code here.
    }
}
Checking account…