Coin Change
Explore how to solve the coin change problem by implementing dynamic programming techniques in Go. Understand how to determine the minimum coins needed to reach a target amount and handle edge cases effectively.
We'll cover the following...
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:
-
coins.length -
coins[i] -
total
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
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.
-1
3
11
0
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.go in the following coding playground.
package mainfunc coinChange(coins []int, total int) int {// Replace this placeholder return statement with your codereturn 0}