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
2
votes
3 answers

Minimum Coin change problem - Backtracking

I'm trying to solve Coin change problem with minimum number of coins using backtracking method. I've actually done with it, but I want to add some option that print the number of coins by its unit not only total amount. this is my python codes…
2
votes
1 answer

Given N coins, each coin can be used at most T times. Is it possible to make value W using minimum N coins?

Input Format: N T (N = number of coins, T = number of times) C1, C2 .... CN W From my solution, I am getting this... Input: 2 4 5 8 37 Output: 5 (Which is valid, because 37 = (8*4)+(5*1)) Input: 2 2 5 10 30 Output: 3 (Here the output should be…
2
votes
1 answer

Coin making problem in DP - getting wrong answer using 2dimensional memo table

When I am passing this Input I am getting wrong answer coin[] = {5,6} Amount(W) = 10 my answer = 1 Correct Answer should be 2 i.e {5,5} void coin_make(int W, vector coin){ int n = coin.size(); int dp[n+1][W+1]; for(int i = 0; i <=W; i++){ …
2
votes
1 answer

Modified Coin Change Problem with Infinite Coins of Denominations of Powers of 5

We are given a set of denominations and a total amount. Infinite coins of each denomination are available All denominations are powers of 5 We have to find the minimum number of coins needed to make the total. I wish to know the logic behind the…
ChocoLite
  • 111
  • 5
2
votes
1 answer

Recursive memoization solutio to solve "count changes"

I am trying to solving the "Counting Change" problem with memorization. Consider the following problem: How many different ways can we make change of $1.00, given half-dollars, quarters, dimes, nickels, and pennies? More generally, can we write a…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
2
votes
1 answer

Generating change given a cash amount and a list of currency

I'm trying to write a program in Prolog, that does two things: Takes two arguments, an integer and a list of integers Is satisfied if change for the first argument can be made from some combination of elements from the second I have come up with a…
Josh
  • 43
  • 6
2
votes
1 answer

Why does my coin change function not work when included with a memoization cache?

I'm attempting the classic coin change problem, my following code works fine, for instance it returns the correct value of 3 with the coin combinations of [1, 2, 5] and a target of 11. However when I add memoization to the recursive calls it comes…
Afs35mm
  • 549
  • 2
  • 8
  • 21
2
votes
1 answer

Coin change problem - brute force solution with backtracking, but how to get coins?

I have a brute force solution with backtracking to solve the coin change problem. Currently i get minimum number of coins that can be used. But how could i also return the coins that were actually used? So for example if the amount is 100 then i…
donald tbd
  • 51
  • 5
2
votes
1 answer

Dynamic programming, minimum number of coins

I have been studying algorithms and data structures off https://runestone.academy/runestone/static/pythonds/index.html, and I got to the part about dynamic programming and the classic minimum number of coins problem. Given a sum we have to figure…
d_darric
  • 387
  • 2
  • 15
2
votes
3 answers

Coin Change Algorithm C

I'm having some trouble coming up with a working algorithm for the following problem. Given determined quantities of available coins from 100, 50, 25 and 10 cents, I need to find how to fit a combination of these coins into a given value x. (it…
Linx
  • 67
  • 7
2
votes
2 answers

Complex Combinatorial Conditions on Dynamic Programming

I am exploring how a Dynamic Programming design approach relates to the underlying combinatorial properties of problems. For this, I am looking at the canonical instance of the coin change problem: Let S = [d_1, d_2, ..., d_m] and n > 0 be a…
2
votes
1 answer

Dynamic Programming for a variant of the coin exchange

I am interested in solving a variant of the coin exchange problem. Recall the formal definition of the coin exchange problem: Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = {S1, S2, .. , Sm}…
2
votes
1 answer

DP Coin Change Algorithm - Retrieve coin combinations from table

To find how many ways we have of making change for the amount 4 given the coins [1,2,3], we can create a DP algorithm that produces the following table: table[amount][coins.count] 0 1 2 3 4 ----------- (0) 1 | 1 1 1 1 1 (1) 2 | 1 1 2 2…
Swordz
  • 35
  • 6
2
votes
2 answers

Change given amount of money to bills

Change the given amount of money into minimum number of bills. Inputs: Amount: positive integer; Bills: a sorted list of distinct positive integers (e.g. [1, 5, 10]). Assumptions: Amount does not exceed 100. At most 4 bill values. Must return 0 if…
Mendal
  • 29
  • 3
2
votes
1 answer

Java Euro Coin Change Denomination

I believe I am having a logical issue with how to develop the section of code responsible for taking the remainder and checking if I can extract change from displayed change categories. It's designed to take a value of how much change you owe back…
Aramza
  • 193
  • 7
  • 29