Given an array of coin denominations and a target amount, return the fewest number of coins needed to make up that amount using unlimited coins of each denomination. Return -1 if the amount cannot be made.
coins = [1,2,5], amount = 113coins = [2], amount = 3-1Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Break a problem into overlapping subproblems along a single dimension — like "the answer up to index i" — solve each one once, and reuse the result instead of recomputing it.
Read the full 1-D Dynamic Programming guide →
Original problem on LeetCode ↗