java.lang.Object
g2101_2200.s2195_append_k_integers_with_minimal_sum.Solution

public class Solution extends Object
2195 - Append K Integers With Minimal Sum.<p>Medium</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. Append <code>k</code> <strong>unique positive</strong> integers that do <strong>not</strong> appear in <code>nums</code> to <code>nums</code> such that the resulting total sum is <strong>minimum</strong>.</p> <p>Return <em>the sum of the</em> <code>k</code> <em>integers appended to</em> <code>nums</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,4,25,10,25], k = 2</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The two unique positive integers that do not appear in nums which we append are 2 and 3.</p> <p>The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.</p> <p>The sum of the two integers appended is 2 + 3 = 5, so we return 5.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [5,6], k = 6</p> <p><strong>Output:</strong> 25</p> <p><strong>Explanation:</strong> The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.</p> <p>The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.</p> <p>The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> <li><code>1 <= k <= 10<sup>8</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimalKSum

      public long minimalKSum(int[] nums, int k)