You are given an array values of distinct positive integers and a positive integer target.
Form a sum equal to exactly target using the given values, where each value may be used any number of times. Among all ways to do this, minimize how many values are used in total.
Return the minimum count, or -1 if target cannot be formed.
Examples
Example 1
Input: values = [1,5,7], target = 11
Output: 3
Explanation: 5 + 5 + 1 = 11 uses three values; no way uses fewer.
Example 2
Input: values = [3], target = 7
Output: -1
Explanation: Multiples of 3 never equal 7, so the target cannot be formed.
Constraints
1≤values.length≤100
1≤target≤104
1≤values[i]≤104
All values are distinct.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up