Preemptive priority scheduler
Your task
Simulate a preemptive priority scheduler with unit-time granularity. Tasks are [name, arrival, burst, priority] where a LOWER priority number means higher priority. At every integer tick, among all arrived, unfinished tasks the scheduler runs the one with the best (lowest) priority; ties broken by earliest arrival, then by input order. A running task can be preempted at any tick by a newly-arrived higher-priority task. Return the execution timeline as a list of (name, start, end) merged slices, where consecutive ticks of the same task on the CPU are coalesced into one slice. The CPU idles (skips) ticks where no task has arrived.
Examples
priority_schedule(tasks: list[list]) -> list[list]Example 1
Input
priority_schedule([["A", 0, 4, 2], ["B", 1, 2, 1]])Output
[["A", 0, 1], ["B", 1, 3], ["A", 3, 6]]