Skip to content
Decoder

Minimize Maximum Pair Sum in Array

Medium

Problem

You are given a list nums of even length n. Split it into n / 2 pairs so that every element is in exactly one pair. The pair sum of a pair is its two values added together. Arrange the pairs to make the largest pair sum as small as possible, and return that value.

Example 1

Input
nums = [3, 5, 2, 3]
Output
7
Why
pairs (3, 3) and (5, 2): max(6, 7) = 7

Example 2

Input
nums = [3, 5, 4, 2, 4, 6]
Output
8
Why
pairs (3, 5), (4, 4), (6, 2)

Constraints

  • n == nums.length
  • 2 <= n <= 10^5
  • n is even.
  • 1 <= nums[i] <= 10^5

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.