Coin Change
Try to solve the Coin Change problem.
We'll cover the following
Statement#
You're given an integer total and a list of integers called coins. The variable coins hold a list of coin denominations, and total is the total amount of money.
You have to find the minimum number of coins that can make up the total amount by using any combination of the coins. If the amount can't be made up, return -1. If the total amount is 0, return 0.
Note: You may assume that we have an infinite number of each kind of coin.
Constraints:
-
coins.length -
coins[i] -
total
Examples#
1 of 4
2 of 4
3 of 4
4 of 4
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Coin Change
What is the minimum number of coins required to make up the following total with the set of coins available to us?
coins = [1, 2, 3, 4] total = 11
-1
3
11
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in main.py in the following coding playground.
Dynamic Programming: Introduction
Solution: Coin Change