A gallery prefetches images with at most limit downloads at once. Download i takes durations[i] ms. Downloads start in index order: at time 0 the first limit start, and whenever one finishes, the next waiting download starts at that moment.
Write prefetchTime(durations, limit) that returns the time when the last download finishes, or 0 if there are none.
Input: durations = [300,100,200,100,400], limit = 2 Output: 700
Tasks 0 and 1 start at 0; 2 starts at 100; 3 and 4 start at 300. Task 4 ends at 300 + 400.
Input: durations = [50,50,50], limit = 5 Output: 50
Everything runs at once.
0 <= durations.length <= 10^3, 1 <= durations[i] <= 10^41 <= limit <= 100Run 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 #747 When Does the Prefetch Finish?. 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.