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