Coin Change
Problem Given an array of coin denominations and a target amount, return the fewest number of coins needed to make up that amount. Each denomination may be used any number of times. If the amount cannot be formed from the given coins, return -1.
Input / Output
- Input: coins (array of distinct positive integers), amount (integer).
- Output: minimum coin count, or -1 if impossible.
Constraints
- 1 ≤ coins.length ≤ 12
- 1 ≤ amount ≤ 10^4
Example
- coins=[1,2,5], amount=11 -> 3 (5+5+1)
- coins=[2], amount=3 -> -1
added …