Questions tagged [coin-change]

All problems (regardless of currency) with making change from a given amount of currency into a number of coins and bills of varying denominations.

All problems with making change from a given amount of currency into a number of coins and bills of varying denominations.

For example, finding the correct number of $20, $10, $5, $1 bills and $0.25, $0.10, $0.05, and $0.01 coins that add up to a given sum.

Variations of the problem are to find any solution, all the solutions, the one with the least number of coins / bills, or with a specific number of them.

260 questions
0
votes
5 answers

Algorithm for the least amount of change

Yes I know there has been similar posts to this however after looking through them all I'm still stuck as I'm very new to programming and none of the answers given were specific enough to my problem to help. Question. Write an efficient ACL…
0
votes
0 answers

Implementing the coin change algorithm with upper and lower limits on composition values

I'm working on a real-world problem where I have theoretical protein sequences and associated experimental protein masses. I'm attempting to decompose the experimental protein masses into all possible compomers of amino acids of known masses to…
michaelmccarthy404
  • 498
  • 1
  • 5
  • 19
0
votes
1 answer

Convert inefficient recursive coin change function to iteration

I have an inefficient recursive coin change function that works out the number of coin combinations for a given amount. I would like to convert it to a more efficient iterative function if possible. One problem is that I am using backtracking to try…
jignatius
  • 6,304
  • 2
  • 15
  • 30
0
votes
1 answer

Dynamic Programming Change Maker

I'm attempting to convert the following algorithm, and I've gotten it mostly working however there's an example from the book I'm using which says I input the denominations of 1,3,4 and a n value of 6 and receive the output of 2. --[[ ALGORITHM…
Rob
  • 403
  • 9
  • 19
0
votes
3 answers

how do you calculate the minimum-coin change for transaction?

Hey everyone. I have a question. I am working on Visual Basic Express and I am supposed to calculate the change from a transaction. Now what code would I use? I have it partly working but its starting to get a little confusing. Thank you. For you…
norris1023
  • 603
  • 3
  • 14
  • 23
0
votes
1 answer

Minimum coin change class giving wrong answer

Trying to [solve] the problem in leetcode (322): You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of…
noman pouigt
  • 906
  • 11
  • 25
0
votes
2 answers

Dynamic Programming - Minimum number of coins needed for given sum

After researching the Coin Change problem I tried my best to implement the solution. The code I have so far prints the minimum number of coins needed for a given sum. However, it does not print out the number of each coin denomination needed. This…
0
votes
0 answers

Why Greedy Coin Change Algorithm is not Showing right result for double values?

On the image the highlighted 0.03 should be 0.04 but showing 0.03 and coin needed should be 10 but showing 9 My Code: #include int main(){ double coins[6] = {0.01,0.05,0.10,0.25,1,2}; double ans[15]; double V = 5.64; …
0
votes
1 answer

Finding out all possible ways of getting a sum from a fixed set of numbers

The question is fairly simple. There is a set {2,4,6}. The expected answer is all possible permutations to get the number 6. So, the answer will be:- { 2,2,2} , {2,4} , {4,2} , {6} What I've tried:- I'm trying to approach this problem using the…
0
votes
0 answers

How to solve UVA 11137

I was trying to solve uva 11137: People in Cubeland use cubic coins. Not only the unit of currency is called a cube but also the coins are shaped like cubes and their values are cubes. Coins with values of all cubic numbers up to 9261 (=…
Tangent
  • 61
  • 1
  • 8
0
votes
3 answers

Exception in CoinChangeProblem code

import java.io.*; public class CoinChangeProblem { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int[] arr; arr = new int[]{1, 2, 5, 10, 20, 50, 100, 500, 1000}; int[] arr2; arr2…
learner
  • 3
  • 3
0
votes
1 answer

algorithm - Coin change in java

I have seen quite many coin change problems and this one is quite unique. I tried using DP and recursion but I wasn't able to solve it. This is the problem: Let's say given a price, X, where X is in cents and I have 5 finite coin denominations,…
0
votes
2 answers

Python Coin Change Dynamic Programming

I am currently trying to implement dynamic programming in Python, but I don't know how to setup the backtracking portion so that it does not repeat permutations. For example, an input would be (6, [1,5]) and the expected output should be 2 because…
0
votes
0 answers

How to make sum of subarray is ZERO with minimum coefficient (similar to coin change algorithm)

I'd like to know how I can express a minimum sum of each coefficient. Sum must be zero, and the list's integer can be multiplied with each coefficient. For ex : (-5, -2, 3, 7) to make sum as 0, if -5 has coefficient 2, 3 has coefficient 1, 7 has…
hohotiger
  • 11
  • 2
0
votes
0 answers

Coin Change: number of solutions when order matters vs. when order doesn't matter

I solved the coin change problem with dynamic programming with the following functions count_distinct and count_perm, which both give the number of solutions for the given amount of money (parameter x) and the coins in use (parameter c). The vector…
user6743763