Job Scheduler
Asked at Figma· Onsite
Reported by the problem's creator, not verified
A scheduler runs jobs on a fixed pool of workers identical workers. Time is an integer clock passed as now with every call, and it never decreases. Each worker runs one job at a time and a job runs without interruption: a job that starts at time s with duration d is running at times s through s + d - 1 and done from s + d onward. A free worker immediately takes the next waiting job, and a worker that finishes at time t can start another job at t.
Examples
Example 1
Input: init =
[2], operations =[["submit",[0,"a",5]],["submit",[0,"b",3]],["submit",[1,"c",2]],["status",[1,"a"]],["status",[1,"c"]],["status",[3,"b"]],["status",[3,"c"]],["status",[5,"a"]],["status",[5,"c"]],["status",[5,"zzz"]]]Output:
[null,null,null,"running","queued","done","running","done","done",null]Explanation: Jobs
aandbstart at time 0 on the two workers;carrives at 1 and queues.bfinishes at 3, socstarts at 3 and finishes at 5, andafinishes at 5. An id that was never submitted has statusNone.