Append K Integers With Minimal Sum LeetCode solution in JavaScript
1var minimalKSum = function (nums, k) {2let total = (k * (k + 1)) / 2;34nums = Array.from(new Set(nums));5nums.sort((a, b) => a - b);6for (let num of nums) {7if (num <= k) {8k++;9console.log(total - 1);10total = total - num + k;11console.log(total + 1);12} else break;13}14return total;15};