Description
Given an integer array nums of 2n integers, group these integers into n pairs such that the sum of min(ai, bi) for all pairs is maximized. Return the maximized sum.
Examples
Input:
nums = [1,4,3,2]Output:
4Explanation:
Pairs (1,2), (3,4): min sums = 1+3 = 4.
Input:
nums = [6,2,6,5,1,2]Output:
9Explanation:
After sorting: [1,2,2,5,6,6]. Optimal pairs are (1,2), (2,5), (6,6) with min values 1+2+6 = 9.
Input:
nums = [7,9]Output:
7Explanation:
With only one pair possible (7,9), the minimum value is 7.
Constraints
- •
1 ≤ n ≤ 10^4 - •
nums.length == 2 * n