40. Coin Change
MediumDynamic programming
Given coin denominations coins (unlimited supply) and an amount, return the fewest coins that make up the amount, or -1 if it cannot be made.
Example 1
Input: coins = [1, 2, 5], amount = 11 Output: 3 Explanation: 5 + 5 + 1
Example 2
Input: coins = [2], amount = 3 Output: -1
Constraints
1 ≤ coins.length ≤ 120 ≤ amount ≤ 10⁴