...

/

Coin Change

Coin Change

Try to solve the Coin Change problem.

Statement

Given an integer total that represents the target amount of money and a list of integers coins that represents different coin denominations, find the minimum number of coins required to make up the total amount. If it’s impossible to achieve the target amount using the given coins, return -1. If the target amount is 0, return 0.

Note: You can assume that we have an infinite number of each kind of coin.

Constraints:

  • 11 \leq coins.length 12\leq 12

  • 11 \leq coins[i] 104\leq 10^4

  • 00 \leq total 900\leq 900

Examples

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

1.

What’s the minimum number of coins required to make up the given total with the following set of coins?

coins = [1, 2, 3, 4].
total = 11.

A.

-1

B.

3

C.

11

D.

0


1 / 4

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.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in main.py in the following coding playground.

Python
usercode > main.py
def coin_change(coins, total):
# Replace this placeholder return statement with your code
return -1
Coin Change

Access this course and 1200+ top-rated courses and projects.