Skip to content

Minimize Maximum Pair Sum in Array

MediumTwo Pointers
Decode it first. Clues, constraints, pattern and plan before any code.

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.

nums = [3, 5, 2, 3]         →  7   (pairs (3, 3) and (5, 2): max(6, 7) = 7)
nums = [3, 5, 4, 2, 4, 6]   →  8   (pairs (3, 5), (4, 4), (6, 2))

Constraints

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