A build server shares one worker between jobs. jobs[i] is how many seconds job i needs, and the jobs wait in a queue in index order. The worker takes the front job and runs it for at most slice seconds. If the job needs no more than that, it finishes; otherwise it goes to the back of the queue with its remaining time.
Write finishOrder(jobs, slice) that returns the job indexes in the order they finish.
Input: jobs = [3,5,2], slice = 2 Output: [2,0,1]
Job 2 fits in its first turn; job 0 finishes on its second turn and job 1 on its third.
Input: jobs = [1,1,1], slice = 1 Output: [0,1,2]
Every job fits in one turn, so they finish in queue order.
1 <= jobs.length <= 1001 <= jobs[i] <= 10001 <= slice <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #260 Round-Robin Finish Order. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.