← All problems

Coin Change

MediumDP

Given coin denominations and an amount, return the FEWEST number of coins to make that amount, or -1 if impossible.

Examples

Input: coins = [1,2,5], amount = 11
Output: 3
5+5+1
Input: coins = [2], amount = 3
Output: -1

Hints

Solution

Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 4 test cases.