Append K Integers With Minimal Sum LeetCode solution in JavaScript

1
var minimalKSum = function (nums, k) {
2
let total = (k * (k + 1)) / 2;
3

4
nums = Array.from(new Set(nums));
5
nums.sort((a, b) => a - b);
6
for (let num of nums) {
7
if (num <= k) {
8
k++;
9
console.log(total - 1);
10
total = total - num + k;
11
console.log(total + 1);
12
} else break;
13
}
14
return total;
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0