Reported May 2025
Temporalsorting

Delayed Task Executor Ordering

Reported by candidates from Temporal's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Temporal OA. Under 2s to a working solution.
Founder's read

Temporal reported this one in May 2025, and it looks friendlier than it is. The story is a delayed executor with condition variables and locks, but the judge version is a pure ordering problem. If you've got an OA in the next couple of days, the real work is spotting that. You compute submitTimes[i] + delays[i] for each task, then order by that value, with the original index as the tiebreaker. A queue-flavored hint is attached, but a priority queue or a plain sort does the job. StealthCoder sits invisibly on your screen as a safety net if you blank on the setup.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that the concurrency paragraph is flavor text. The function is deterministic, so nothing waits or wakes. Build the runnable time for each index, sort the indices by (runnable, index), and map them to task IDs. That's O(n log n), fine for 200000 tasks. The mistake that sinks a first attempt is sorting by delay alone, or by submit time alone. Example 1 shows why: task a has the biggest delay but b and c run first because of their own sums. The second pitfall is overflow. Values reach 10^12, so use 64-bit longs and never 32-bit ints. Sorting must also be stable, or carry the index explicitly in the comparator. Don't implement a real executor with threads. If the setup throws you mid-assessment, StealthCoder can surface the sort-by-pair solution fast so you don't burn time overthinking the lock language.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Delayed Task Executor Ordering cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Temporal's OA.

Temporal reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Delayed Task Executor Ordering FAQ

How hard is the Temporal delayed executor question really?+

Easy once you ignore the production-style description. It's computing a deadline per task and sorting. The difficulty is psychological, because the condition variable talk makes it sound like a concurrency design question. The function itself needs no threads, locks, or timers.

What's the trick to getting the ordering right?+

Sort by the pair (submitTimes[i] + delays[i], i). The first element is the runnable time and the second is the original index, which handles ties. Example 2 tests this: all three deadlines equal 5, so the output stays in input order.

Do I need a priority queue or is sorting enough?+

Sorting is enough, since all tasks are known upfront. A min-heap keyed on (runnable, index) also works and gives the same result. Sorting indices with a comparator is shorter and less error-prone, so it's the safer pick under time pressure.

What edge cases should I check before submitting?+

Check zero delays, like Example 3. Check ties on runnable time. Check large values near 10^12, where you need 64-bit arithmetic. Also confirm you return task IDs, not indices or runnable times, and that the output length matches the input.

How do I prepare for this in 48 hours?+

Write a custom-comparator sort on pairs in your language and practice tie-breaking by index. Run the three examples by hand. Then do two or three similar scheduling or merge-by-key problems. You don't need threading knowledge for this version of the question.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Temporal.

OA at Temporal?
Invisible during screen share
Get it