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

Trying to solve this puzzle but didn't find the right answer. Here is the code generated

You have coins of values 5, 10, 20, 50, 100 whose weights are respectively 2g, 3g, 10g, 25g, 50g. Your purse is weak so you cannot exceed the weight of 391g. And you can put inside it only 3 coins having the same value. Can you say what is the…
2
votes
1 answer

Coin change (coin values are powers of m)

Below problem was in a contest (it's over now) contest link. Its seems variant of classic coin denomination problem - Given an array(k elements) having coin values and a number n. We need to answer the number of ways we can make the denomination of…
2
votes
3 answers

C program counting coins with while loops

I've seen this particular C program mentioned quite a bit, albeit in some different forms. However I cannot seem to identify the source of my problem, or find another answer that helps. The program compiles and even executes correctly except for a…
Rory
  • 33
  • 1
  • 4
2
votes
1 answer

Memoization: Making change with coins

I am working on the classic making change with coins problem with Python. This is my implementation. def memo(fn): def helper(*args): # here, * indicate the fn take arbitrary number of argumetns d = {} if args in d: …
2
votes
2 answers

Stack overflow in my haskell code

I wanna find all combinations for coin change. 1, 2, 5, 10, 20, 50, 100 und 200. ( 1 cent , 2cent ..) if coin is over 500 (5 euro) , it should give -1.My code works perfectly with those testcases: numOfSplits 10 (11) numOfSplits 20 (41) …
Mert
  • 55
  • 8
2
votes
1 answer

Pseudo code into logical steps?

I am trying to solve the coin-change problem: Given a list of number , k , how many ways are there to give change to a given amount m. As one of the resource I have the following pseudo code: (define (count-change amount) (cc amount 5)) (define…
Bula
  • 2,398
  • 5
  • 28
  • 54
2
votes
3 answers

Backtracking in Standard ML

I have seen in my SML manual the following function, which computes how many coins of a particular kind are needed for a particular change. For example change [5,2] 16 =[5,5,2,2,2] because with two 5-coins and three 2-coins one gets 16. the…
Radu
  • 384
  • 4
  • 15
2
votes
5 answers

Coin change problem with infinite number of coins of each denomination

I want to know the idea of algorithm for the coin change problem where each denomination has infinte number of coins. Means how to apply DP (like the standard coin change problem) For e.g in set 1,10,15, change for 35 gives--2 coins of 10 and one…
avd
  • 13,993
  • 32
  • 78
  • 99
1
vote
1 answer

Find coins which sum to target amount with a restricted set

Given a sum amount 1.15 Rs. (1 Rs. = 100 Paise), so total 115 paise and given a list of 8 coins with denominations as {1, 2, 5, 10, 20, 25, 50, 100} paise. Find 6 coins which sum to 1.15 Rs. The constraint is that I should not be able to give change…
Rajendra Uppal
  • 19,218
  • 15
  • 59
  • 57
1
vote
2 answers

visual c++ coin change system for dispensing machines

recently i've been given an assignment to work on a new project in c++...and i've been doing some thinking for some days and nights on how to approach it....unfortunately the thinking hasn't worked out and currently struggling on the designing…
j.li
  • 11
  • 2
1
vote
4 answers

Beginning Dynamic Programming - Greedy coin change help

I am currently working through a book on algorithm design and came across a question whereby you must implement a greedy algorithm with dynamic programming to solve the coin change problem. I was trying to implement this and I just can't figure out…
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180
1
vote
0 answers

Why does my solution not work for coin change problem?

At every recursive call I choose 1 more of current denomination or no more of current denomination. I sort the denominations in descending order and use a cache of seen remaining amount. Since I try the higher denomination combinations first, the…
Thomas
  • 6,032
  • 6
  • 41
  • 79
1
vote
1 answer

Calculating currency combinations efficiently

In the game Team Fortress 2, weapon, metal, and keys are used as currencies. Metal is subdivided into three types: scrap, reclaimed, and refined (from now on "scrap", "rec" and "ref"), and it is the latter that is the reference for the others: 1…
1
vote
0 answers

Coin change problem with constraint: at most two coins in each denomination

I am studying recursive formulas in the famous coins problem in dynamic programming. However, I cannot solve this variation where there is a constraint where each coin (a power of two) could be used at most twice. I know the recursive formula for…
1
vote
2 answers

Understanding a LeetCode recursion problem in Python (322 Coin Change)

Leetcode Question: https://leetcode.com/problems/coin-change/ 322 Coin Change: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of…