A CI server has one runner and a queue of build jobs that all arrived at the same moment. Job i takes durations[i] minutes. Jobs run one after another, and each job waits from the start until it begins running.
Write smallestTotalWait(durations) that returns the smallest possible sum of every job's waiting time, if you may run the jobs in any order.
Input: durations = [3,1,2] Output: 4
Run 1, then 2, then 3: they wait 0, 1, and 3 minutes, for a total of 4.
Input: durations = [5] Output: 0
A single job starts right away.
0 <= durations.length <= 1000001 <= durations[i] <= 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 #573 Shortest Total Wait for Build Jobs. 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.