|
| 1 | +## [1877. Minimize Maximum Pair Sum in Array](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/) |
| 2 | + |
| 3 | +The **pair sum** of a pair `(a,b)` is equal to `a + b`. The **maximum pair sum** is the largest **pair sum** in a list of pairs. |
| 4 | + |
| 5 | +- For example, if we have pairs `(1,5)`, `(2,3)`, and `(4,4)`, the **maximum pair sum** would be `max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8`. |
| 6 | + |
| 7 | +Given an array `nums` of **even** length `n`, pair up the elements of `nums` into `n / 2` pairs such that: |
| 8 | + |
| 9 | +- Each element of `nums` is in **exactly one** pair, and |
| 10 | +- The **maximum pair sum** is **minimized**. |
| 11 | + |
| 12 | +Return _the minimized **maximum pair sum** after optimally pairing up the elements_. |
| 13 | + |
| 14 | +#### Example 1: |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> nums = [3,5,2,3] |
| 18 | +<strong>Output:</strong> 7 |
| 19 | +<strong>Explanation:</strong> The elements can be paired up into pairs (3,3) and (5,2). |
| 20 | +The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7. |
| 21 | +</pre> |
| 22 | + |
| 23 | +#### Example 2: |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> nums = [3,5,4,2,4,6] |
| 27 | +<strong>Output:</strong> 8 |
| 28 | +<strong>Explanation:</strong> The elements can be paired up into pairs (3,5), (4,4), and (6,2). |
| 29 | +The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8. |
| 30 | +</pre> |
| 31 | + |
| 32 | +#### Constraints: |
| 33 | + |
| 34 | +- `n == nums.length` |
| 35 | +- <code>2 <= n <= 10<sup>5</sup></code> |
| 36 | +- `n` is **even**. |
| 37 | +- <code>1 <= nums[i] <= 10<sup>5</sup></code> |
0 commit comments