Skip to the code
cf.
+25 XP

#170 Build Runner Capacity

medium

A CI system must run a queue of build jobs in order. jobs[i] is how many minutes job i takes. Each day, the runner works through the queue from where it stopped, but it can't start a job that would push the day's total past its daily capacity in minutes. Jobs can't be split across days.

Write minCapacity(jobs, days) that returns the smallest daily capacity that finishes all jobs within days days.

Example 1

Input: jobs = [3,2,2,4,1,4], days = 3
Output: 6

With capacity 6 the days are [3, 2], [2, 4], [1, 4]. Capacity 5 would need 4 days.

Example 2

Input: jobs = [1,2,3,1,1], days = 4
Output: 3

Days [1, 2], [3], [1, 1] fit in capacity 3.

Constraints

  • 1 <= days <= jobs.length <= 50000
  • 1 <= jobs[i] <= 500
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).