Skip to the code
cf.
+25 XP

#295 Balance Two Deploy Queues

medium

A CI system has two build machines. Each job in durations takes that many minutes, and every job must run on exactly one machine.

Write minQueueDifference(durations) that splits the jobs between the two machines so that their total minutes are as close as possible, and returns the smallest possible difference between the two totals.

Example 1

Input: durations = [3,1,4,2,2]
Output: 0

3 + 1 + 2 = 6 on one machine and 4 + 2 = 6 on the other.

Example 2

Input: durations = [10,3]
Output: 7

One job per machine is the best split: 10 - 3 = 7.

Constraints

  • 1 <= durations.length <= 16
  • 1 <= durations[i] <= 1000
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).