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:4
Explanation:

Pairs (1,2), (3,4): min sums = 1+3 = 4.

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

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:7
Explanation:

With only one pair possible (7,9), the minimum value is 7.

Constraints

  • 1 ≤ n ≤ 10^4
  • nums.length == 2 * n

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!