Minimize Maximum Pair Sum in Array - Problem

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.

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.

Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:

  • Each element of nums is in exactly one pair, and
  • The maximum pair sum is minimized.

Return the minimized maximum pair sum after optimally pairing up the elements.

Input & Output

Example 1 — Basic Case
$ Input: nums = [3,5,2,4]
Output: 7
💡 Note: After sorting [2,3,4,5], pair (2,5) and (3,4). Maximum pair sum is max(7,7) = 7
Example 2 — Larger Array
$ Input: nums = [3,5,4,2,4,6]
Output: 8
💡 Note: After sorting [2,3,4,4,5,6], pair (2,6), (3,5), (4,4). Maximum pair sum is max(8,8,8) = 8
Example 3 — Minimum Size
$ Input: nums = [1,4]
Output: 5
💡 Note: Only one pair possible: (1,4) with sum 5

Constraints

  • 2 ≤ nums.length ≤ 105
  • nums.length is even
  • 1 ≤ nums[i] ≤ 105

Visualization

Tap to expand
Minimize Maximum Pair Sum: [3,5,2,4]Step 1: Input3524Step 2: Sort & Pair23452+5=73+4=7Step 3: ResultMax Pair Sum7Optimal strategy: Pair smallest with largest elementsResult: 7 (minimized maximum pair sum)
Understanding the Visualization
1
Input Array
Given array of even length that needs pairing
2
Sort & Pair
Sort array and pair smallest with largest
3
Find Maximum
Return the maximum sum among all pairs
Key Takeaway
🎯 Key Insight: Pairing smallest with largest elements minimizes the maximum pair sum
Asked in
Google 12 Facebook 8 Amazon 6
89.2K Views
Medium Frequency
~15 min Avg. Time
1.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen