Minimum Coins
Given distinct positive denominations coins and a positive amount, return the fewest coins whose values sum exactly to amount. Each denomination can be used…
Given distinct positive denominations coins and a positive amount, return the fewest coins whose values sum exactly to amount. Each denomination can be used any number of times. Return -1 if no exact payment exists. The input order does not affect the answer.
- 1 <= number of denominations <= 100. - Denominations are distinct integers from 1 through 1000, in any order. - 1 <= amount <= 1000. - The visualizer accepts at most 6 denominations and amount at most 10; larger valid inputs are coding-only.
Example 1: input coins = [1,3,4], amount = 6; output 2. Two denomination-3 coins beat greedy 4+1+1.
Example 2: input coins = [4], amount = 8; output 2. Two copies of denomination 4 make the exact amount.
Example 3: input coins = [6,10], amount = 7; output -1. No nonnegative combination totals 7.
Category: Arrays. Topic: dynamic-programming. Difficulty: hard. Patterns: dynamic-programming.