Loading...
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.
Input: values = [1,5,7], target = 11
Output: 3
Explanation: 5 + 5 + 1 = 11 uses three values; no way uses fewer.
Input: values = [3], target = 7
Output: -1
Explanation: Multiples of 3 never equal 7, so the target cannot be formed.
values.length ≤100target ≤104values[i] ≤104Click "Run" to test with sample cases or "Submit" to run all tests.