Pair Array Sum
ARRAY
MATH

Problem

Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.

Examples

arrayPairSum([5, 8, 2, 4]) // returns 7 // The optimal pairing is (2, 4) and (5, 8) // leading to a sum of 2 + 5 = 7. arrayPairSum([7, 3, 7, 6, 4, 5]) // returns 15 // The optimal pairing is (3, 4), (5, 6), and (7, 7) // leading to a sum of 3 + 5 + 7 = 15. arrayPairSum([9, 3, 8, 7]) // returns 11 // The optimal pairing is (3, 7) and (8, 9) // leading to a sum of 3 + 8 = 11.
Loading...