Loading...
Loading...
You are given a list of positive integers nums and an integer k.
Consider an operation where you choose two elements of nums at different positions, take the absolute difference of their values, and append it to the end of nums. Each operation makes nums one element longer. Later operations can also choose the elements that earlier operations appended.
Given that you can perform this operation at most k times, return the smallest possible value of the minimum element of nums.
Note that k can be 0, in which case nums stays as it is.
Input: nums = [4, 2, 5, 9, 3], k = 1
Output: 1
Explanation: Choose 4 and 5 and append 1. Every element of nums is at least 2, and no two elements are equal, so a single operation cannot produce 0.
Input: nums = [10, 14, 22], k = 2
Output: 2
Explanation: Choose 10 and 22 and append 12, giving [10, 14, 22, 12]. Then choose 14 and 12 and append 2. With one operation the best you can do is 4, from 10 and 14.
Input: nums = [42, 47, 50, 54, 62, 79], k = 2
Output: 3
Explanation: Choose 47 and 50 and append 3. A second operation cannot do better: no two original elements differ by less than 3, and no appended difference lies within 2 of an original element.
Input: nums = [7, 100], k = 3
Output: 0
Explanation: Choose 7 and 100 twice, appending 93 both times. Then choose the two copies of 93 and append 0.
nums.length ≤2000nums[i] ≤109k ≤109