Lightest Heaviest Pair
weights has an even number of items. Split the items into pairs, every item in exactly one pair, so that the heaviest pair (the pair with the largest total weight) is as light as possible. Return that smallest possible total weight of the heaviest pair.
Example 1
weights [3,5,2,3]
returns 7
Pair 2 with 5 and 3 with 3: the pair totals are 7 and 6, so the heaviest pair weighs 7. Pairing 5 with 3 would give a pair of 8.
Example 2
weights [3,5,4,2,4,6]
returns 8
Sorted, the weights are 2, 3, 4, 4, 5, 6. Pairing 2 with 6, 3 with 5 and 4 with 4 makes every pair weigh 8.
Constraints
2 <= len(weights) <= 100, andlen(weights)is even1 <= weights[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.