Code RoomPreemptive priority scheduler
HardPrep Room Coding #295

Preemptive priority scheduler

CodingAlgorithms & data structuresMid–Senior~30 min

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.

Implement
priority_schedule(tasks: list[list]) → list[list]
Examples
in[[["A",0,4,2],["B",1,2,1]]]out[["A",0,1],["B",1,3],["A",3,6]]
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 30 min
InputExpectedGot
[[["A",0,4,2],["B",1,2,1]]][["A",0,1],["B",1,3],["A",3,6]]not run yetsample