Minimum Sum

Day 41
Input: [1,4,3,2]

Output: 4
Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
var arrayPairSum = function(nums) {
nums.sort((a, b) => a - b);
minSum = 0;
for (let i = 0; i < nums.length; i += 2) {
minSum += Math.min(nums[i], nums[i + 1]);
}
return minSum;
};

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Setu Potnis

Setu Potnis

6 Followers

A university student wanting to learn more as well as share my journey about learning software