A dashboard loads its widgets' data with at most limit requests in flight, starting requests in index order (the first limit at time 0, then each next one as soon as any request finishes). Request i takes durations[i] ms.
Widgets render as soon as their data arrives. Write completionOrder(durations, limit) that returns the request indexes in the order they finish. Requests that finish at the same time are listed by index, smallest first.
Input: durations = [300,100,200,100,400], limit = 2 Output: [1,0,2,3,4]
Finish times are 300, 100, 300, 400, 700. Requests 0 and 2 tie at 300, so 0 comes first.
Input: durations = [5,4,3], limit = 3 Output: [2,1,0]
All start together, so the shortest finishes first.
0 <= durations.length <= 10^4, 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 #749 Completion Order of Batched Requests. 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.