Basic example
Input
coins = [1, 2, 5], amount = 11
Output
3
11 can be made with 5 + 5 + 1 => 3 coins, which is minimum.
Full lesson preview
Given coin denominations and a target amount, compute the minimum number of coins needed to make that amount, or -1 if impossible.
Problem statement
Task
Examples
Input
coins = [1, 2, 5], amount = 11
Output
3
11 can be made with 5 + 5 + 1 => 3 coins, which is minimum.
Input format
Output format
Constraints
Samples
Input
coins = [2], amount = 3
Output
-1
3 cannot be formed with only coin 2.