Skip to the code
cf.
+25 XP

#748 Upload Finish Times

medium

An upload widget sends files with at most limit uploads in flight. Upload i takes durations[i] ms. Uploads start in index order: the first limit start at time 0, and whenever one finishes, the next waiting upload starts at that same moment.

Write finishTimes(durations, limit) that returns the finish time of every upload, in index order. There can be 100,000 uploads and a limit of up to 100,000.

Example 1

Input: durations = [300,100,200,100,400], limit = 2
Output: [300,100,300,400,700]

Upload 2 starts at 100 when upload 1 finishes; uploads 3 and 4 start at 300.

Example 2

Input: durations = [5,5,5], limit = 1
Output: [5,10,15]

With one slot, uploads run one after another.

Constraints

  • 0 <= durations.length <= 10^5, 1 <= durations[i] <= 10^4
  • 1 <= limit <= 10^5
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).