Engineering platform~10 min2s · 256 MBtarget O(n) time, O(n) spaceclassic twin: lc-1480traversal
You work on the build system behind an app. Builds run on many machines at once, so each build uses some machine-minutes: the minutes of every machine it occupied, added up. A build can use up to 100,000 machine-minutes.
Your team lead says: "Finance wants a dashboard that shows, after each build, how many machine-minutes the day has used so far."
The list holds the machine-minutes of each build, in the order the builds finished. You return the day's total after every build.
Write running_build_minutes(minutes).
minutes[i] is the machine-minutes used by build i. Builds are listed in the order they finished.totals with one value per build.totals[i] is minutes[0] + minutes[1] + ... + minutes[i].Input: minutes = [3, 1, 4, 1, 5]
Output: [3, 4, 8, 9, 14]Each row is one build. The total after a build is the total before it plus its minutes.
| Build | Minutes | Total after the build |
|---|---|---|
| 0 | 3 | 3 |
| 1 | 1 | 4 |
| 2 | 4 | 8 |
| 3 | 1 | 9 |
| 4 | 5 | 14 |
The last total is 14.
Input: minutes = [0]
Output: [0]One build that used nothing gives a total of 0.
Input: minutes = [100000, 100000, 100000]
Output: [100000, 200000, 300000]Three builds of 100,000 minutes each give totals of 100,000, 200,000 and 300,000.
1 ≤ minutes.length ≤ 100,000 (builds in the day)0 ≤ minutes[i] ≤ 100,000 (machine-minutes of one build)Adding every prefix again costs n(n - 1) / 2 additions, which is 4,999,950,000 at the largest size. That is too many for the time limit, so you add each build once. The final total can reach 10^5 × 10^5 = 10^10, above the 32-bit limit of 2,147,483,647, so the total needs 64 bits.