Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Array Partition

Easy

Topics
ArrayGreedySorting

Given an array nums of 2n integers, group them into n pairs so that the sum of min(pair) over all pairs is maximized, and return that maximum sum.

Example 1

Input:  nums = [1,4,3,2]
Output: 4
Explanation: Pairs (1,2) and (3,4) give 1 + 3 = 4.

Example 2

Input:  nums = [6,2,6,5,1,2]
Output: 9

Constraints

  • 1 <= n <= 10^4
  • nums.length == 2n
  • -10^4 <= nums[i] <= 10^4
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access