Append K Integers With Minimal Sum

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
Inputnums = [1,4,25,10,25], k = 2
Output5
The two unique positive integers appended are 2 and 3, and their sum is 5.
Example 2
Inputnums = [5,6], k = 6
Output25
The six unique positive integers appended are 1, 2, 3, 4, 7, and 8, and their sum is 25.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9
  • 1 <= k <= 10^8

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate