#1877

Minimize Maximum Pair Sum in Array

pupil · 430 · lc medium +25 · verified · 83.3% accepted · 2,367 likes · top 95%

Description

For two numbers a and b, their pair sum is a + b. Given an even-length integer array nums, partition its elements into n / 2 pairs (each element in exactly one pair) to minimize the largest pair sum.

Return that minimized maximum pair sum.

Example 1:

Input: nums = [3,5,2,3]
Output: 7
Explanation: The elements can be paired up into pairs (3,3) and (5,2).
The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.

Example 2:

Input: nums = [3,5,4,2,4,6]
Output: 8
Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).
The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.

Code

1
2
3