FastPrepDelayed Task Executor Ordering

Delayed Task Executor Ordering

Temporal logoTemporal● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A delayed executor accepts tasks at their submission times and makes each task runnable at submitTimes[i] + delays[i].

For this deterministic judge adapter, return task IDs in execution order: earlier runnable time first, breaking equal runnable times by the original submission index.

A production implementation should wait on a condition variable for the earliest deadline, wake when a new earlier task is submitted, and avoid polling or sleeping while holding a lock.

Function

delayedExecutionOrder(taskIds: String[], submitTimes: long[], delays: long[]) → String[]

Examples

Example 1

taskIds = ["a","b","c"]submitTimes = [0,2,4]delays = [10,1,3]return = ["b","c","a"]

The runnable times are 10, 3, and 7.

Example 2

taskIds = ["first","second","third"]submitTimes = [0,1,2]delays = [5,4,3]return = ["first","second","third"]

All deadlines equal 5, so original indices break the tie.

Example 3

taskIds = ["only"]submitTimes = [100]delays = [0]return = ["only"]

The only task executes at its submission time.

Constraints

  • 1 <= taskIds.length == submitTimes.length == delays.length <= 200000.
  • Task IDs are unique non-empty strings.
  • 0 <= submitTimes[i], delays[i] <= 10^12, and each sum fits in a signed 64-bit integer.

More Temporal problems

See Temporal hiring insights
public String[] delayedExecutionOrder(String[] taskIds, long[] submitTimes, long[] delays) {
    // Write your code here.
}
taskIds["a","b","c"]
submitTimes[0,2,4]
delays[10,1,3]
expected["b", "c", "a"]
Checking account…