Deterministic task scheduler
Simulate a deterministic single-threaded timer event loop. You are given tasks as [scheduled_time, duration, id]. The loop processes tasks in order of scheduled_time; ties are broken by lower id. The CPU runs one task at a time to completion (no preemption). A task cannot start before its scheduled_time; if the CPU is busy past that time, it starts when the CPU frees, and if the CPU is idle before scheduled_time, the loop waits. Return a list of [id, start_time, end_time] in execution order.
Implement
event_loop(tasks: list[list[int]]) → list[list[int]]Examples
in
[[[0,5,1],[2,3,2]]]out[[1,0,5],[2,5,8]]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 40 min
solution.py
InputExpectedGot
[[[0,5,1],[2,3,2]]][[1,0,5],[2,5,8]]not run yetsample