Job Scheduler

Asked at Figma· Onsite

Reported by the problem's creator, not verified

Import another question

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

  1. 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 a and b start at time 0 on the two workers; c arrives at 1 and queues. b finishes at 3, so c starts at 3 and finishes at 5, and a finishes at 5. An id that was never submitted has status None.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.