A paint seller only sells paint in certain amounts e.g. in 5, 7, 12 liters. Given the list of the amounts the paint seller sells and a list of amounts that you want to buy, calculate the minimum wasted paint.
Example
paintSizes: [5, 7, 9]
paintNeeded: [10, 11, 15, 13]
output: 2
Explanation: to get 10 litres, we can buy the 5 litres twice, so no wasted paint, then to get 11 litres, we need to buy 5 litres and 7 litres, so we waste 1 litre of paint, then to get 15 litres, we can buy 5 litres 3 times so theres no waste, then to get 13 litres, we can buy 5 litres and 9 litres so we waste 1 litre.
In total, we wasted 2 litres.Is the crux of the question: given an array of integers and a target integer, how can we sum up integers in the array such that the sum is the lowest possible sum larger than or equal to the target?
I thought binary search might work, but could not figure it out.