Skip to the code
cf.
+10 XP

#260 Round-Robin Finish Order

easy

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.

Example 1

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.

Example 2

Input: jobs = [1,1,1], slice = 1
Output: [0,1,2]

Every job fits in one turn, so they finish in queue order.

Constraints

  • 1 <= jobs.length <= 100
  • 1 <= jobs[i] <= 1000
  • 1 <= slice <= 1000
Saved in this browser

Run 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).