Write a function that finds the minimum number of coins needed to make a given amount with an array of available denominations.
HardProblem Statement
Write a function that finds the minimum number of coins needed to make a given amount with an array of available denominations.
Sample Input
amount = 11, coins = [ 1, 5, 6 ]
Sample Output
2
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Find the minimum number of coins needed for a given amount
function minCoins(amount, coins) {
// Initialize an array to store the minimum coins for each amount up to the given amount
// Update the array using dynamic programming approach
}
console.log(minCoins(11, [ 1, 5, 6 ]));
Input
amount = 11, coins = [ 1, 5, 6 ]
Expected Output
2