Delayed Task Executor Ordering
Updated
Problem statement
A delayed executor accepts tasks at their submission times and makes each task runnable at submitTimes[i] + delays[i].
In this practice version, 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 interview questions
Similar questions at other companies
- Top K With a Deterministically Noisy Comparator (MLE)Mercor · ONSITE INTERVIEWMercor interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Streaming Median of Trade PricesXantium · PHONE SCREEN
- Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
- Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
- Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
- Finish Time of Fixed-Length CPU TasksGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions