The list coins holds the values of the coins you have, for example 1, 5 and 10 rupee coins. You have as many coins of each value as you need.
Make the exact total amount using as few coins as possible, and return how many coins you used. If the total cannot be made with these coins, return -1.
Examples
Example 1:
Input: coins = [1,5,10], amount = 27
Output: 5
Explanation: 27 = 10 + 10 + 5 + 1 + 1. That is 5 coins, and no smaller count works.
Example 2:
Input: coins = [4,6], amount = 9
Output: -1
Explanation: Every sum of 4s and 6s is even, so 9 cannot be made.
Example 3:
Input: coins = [3], amount = 0
Output: 0
Explanation: A total of 0 needs no coins.