Class Solution
-
- All Implemented Interfaces:
public final class Solution2195 - Append K Integers With Minimal Sum\.
Medium
You are given an integer array
numsand an integerk. Appendkunique positive integers that do not appear innumstonumssuch that the resulting total sum is minimum.Return the sum of the
kintegers appended tonums.Example 1:
Input: nums = 1,4,25,10,25, k = 2
Output: 5
Explanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.
The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.
The sum of the two integers appended is 2 + 3 = 5, so we return 5.
Example 2:
Input: nums = 5,6, k = 6
Output: 25
Explanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.
The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.
The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>9</sup></code>
<code>1 <= k <= 10<sup>8</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongminimalKSum(IntArray nums, Integer k)-
-
Method Detail
-
minimalKSum
final Long minimalKSum(IntArray nums, Integer k)
-
-
-
-