{ "id": 2305, "name": "append-k-integers-with-minimal-sum", "difficulty": "Medium", "link": "https://leetcode.com/problems/append-k-integers-with-minimal-sum/", "date": "2022-02-27", "task_description": "You are given an integer array `nums` and an integer `k`. Append `k` **unique positive** integers that do **not** appear in `nums` to `nums` such that the resulting total sum is **minimum**. Return_ the sum of the_ `k` _integers appended to_ `nums`. **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:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109` `1 <= k <= 108`", "test_case": [ { "label": "Example 1", "input": "nums = [1,4,25,10,25], k = 2", "output": "5 " }, { "label": "Example 2", "input": "nums = [5,6], k = 6", "output": "25 " } ], "constraints": [ "1 <= nums.length <= 105", "1 <= nums[i] <= 109", "1 <= k <= 108" ], "python_template": "class Solution(object):\n def minimalKSum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ", "java_template": "class Solution {\n public long minimalKSum(int[] nums, int k) {\n \n }\n}", "metadata": { "func_name": "minimalKSum" } }