Given an integer array `nums` of `2n` integers, group them into `n` pairs `(a1, b1), (a2, b2), ..., (an, bn)` so that the sum of `min(ai, bi)` over all pairs is as large as possible. Return that maximum sum.
Given an integer array nums of 2n integers, group them into n pairs (a1, b1), (a2, b2), ..., (an, bn) so that the sum of min(ai, bi) over all pairs is as large as possible. Return that maximum sum.
Example 1:
Input: {"nums":[1,4,3,2]}
Output: 4
Constraints:
1≤n≤104
nums.length==2n
−104≤nums[i]≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,4,3,2]}
4 numbers must become 2 pairs; each pair only scores its smaller number.