I have list of numbers where numbers can be repeated, so list may look like:
[18,18,18,15,15,15,11,11,11]
I also have one number that we'll call the target. My goal is to find a set of numbers from my list that ideally sum to the target, or else are as close as possible without going over.
If target is 88
, then ideal result should be: [18,18,15,15,11,11]
, as remainder is 0 in this case.
One more example:
List: [60,50,50,30,20]
target: `105`
Expected result: [50,50] (or may be [50,30,20])
Currently I'm first finding all possible combinations from the list numbers, and then extracting combination values from target, until remainder gets lower possible value, but that is very inefficient way, as all possible combinations count sometime gets very large number.
What may be better/efficient way for this?