weights of even length holding the box weights. Split all boxes into pairs so that every box belongs to exactly one pair.
The weight of a bundle is the sum of its two boxes. You want the heaviest bundle to be as light as possible. Return its weight under the best pairing.weights=[4, 1, 7, 6] → 10
Pairs (1, 7) and (4, 6) give sums 8 and 10. Putting 6 and 7 together would give 13, which is worse. The answer is 10.
weights=[5, 5, 2, 8, 3, 7] → 10
Pairs (2, 8), (3, 7) and (5, 5) all sum to 10.
weights=[9, 9] → 18
len(weights) ≤ 10⁵len(weights) is evenweights[i] ≤ 10⁵weights=[4, 1, 7, 6]
10
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.