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

Converting a recursion problem code from Python to Common Lisp

I'm trying to convert a recursion problem written in Python (the 4th problem here see its repo page for details) into (Common) Lisp Here is the Python code which I've edited slightly for readability: def coin(target,coins,res): # Default output…
Lars Malmsteen
  • 738
  • 4
  • 23
5
votes
3 answers

Thought process for arriving at dynamic programming solution of Coins change problem

I am learning dynamic programming and came across this famous coins change problem. The reccurence relation to solve this problem is given by countCoinsChangeRec(arr, sum - arr[i], i) + countCoinsChangeRec(arr, sum, i - 1); The simplest way to…
Arun Gowda
  • 2,721
  • 5
  • 29
  • 50
5
votes
1 answer

What is the time complexity of this coin change algorithm?

I solved the coin changing problem on leetcode https://leetcode.com/problems/coin-change-2/. This is the code I wrote: def change(self, amount: int, coins: List[int]) -> int: def helper(amount, coins, ind): if amount == 0: …
5
votes
2 answers

Coin change with limited number of coins

I have written a program for generating subset sum which might be used in this problem which states: Suppose, you have 3 $1-coins, 2 $2-coins, 3 $5-coins, 1 $10-coin, there are 4 ways to obtain $10 from those coins. If there are n1 $X1 …
4
votes
4 answers

Arithmetics in Prolog, represent a number using powers of 2

I have two numbers, let's name them N and K, and I want to write N using K powers of 2. For example if N = 9 and K = 4, then N could be N = 1 + 2 + 2 + 4 (2^0 + 2^1 + 2^1 + 2^2). My program should output something like N = [1,2,2,4]. I am used to…
4
votes
2 answers

Coin change dynamic-programming question top-down memoization approach

I'm currently working on the coin change dynamic-programming question on leetcode -- https://leetcode.com/problems/coin-change/. Here is the question statement: You are given coins of different denominations and a total amount of money amount. Write…
Wonjoo Lee
  • 99
  • 3
  • 8
4
votes
1 answer

Minimum coin change problem with limited amount of coins

To be specific, the problem is: Given array of denominations coins[], array of limit for each coins limits[] and number amount, return minimum number of coins needed, to get the amount, or if it's not possible return null. Additionally fill array…
Mr Patience
  • 1,564
  • 16
  • 30
4
votes
3 answers

How to get the least possible combination for a coin change problem in C# using recursion

I'm quite new to C# and I have a recursion issue to solve. I want to get the least number of coins possible in this coin change problem. I've adapted an algorithm to it but I need to return an object of type Change which will contain the minimum…
TropicalViking
  • 407
  • 2
  • 9
  • 25
4
votes
2 answers

Greedy Coin Change Time Complexity

I'm trying to figure out the time complexity of a greedy coin changing algorithm. (I understand Dynamic Programming approach is better for this problem but I did that already). I'm not sure how to go about doing the while loop, but I do get the for…
RiseWithMoon
  • 104
  • 2
  • 8
4
votes
1 answer

Dynamic change-making algorithm that returns actual list of coins used

I'm trying to adjust the code from the wikipedia: https://en.wikipedia.org/wiki/Change-making_problem#Implementation To also output the list of coins used, not only the number of coins used. That is, for instance: change_making([6, 8, 12], 52)…
emihir0
  • 1,200
  • 3
  • 16
  • 39
4
votes
1 answer

Why this solution isn't working for the coin change algorithm?

Write a program that, given the amount N to make change for and the number of types of m infinitely available coins, and a list of m coins, prints out how many different ways you can make change from the coins to STDOUT. My intuition was, for each…
Jared
  • 578
  • 7
  • 21
4
votes
5 answers

Printing which coins are used to make a given amount

I am trying to use recursion to find the minimum amount of coins to make a given amount. I have code that is able to list the minimum amount of coins required, but I can't seem to find a way to print off which coins were used to come up with the…
Sigonious
  • 43
  • 1
  • 5
3
votes
4 answers

How can I use dynamic programming in Scheme to solve the Coin Change problem?

I'm trying to learn a Lisp language and have settled on Guile and am trying to solve this problem: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return…
Kyle Baldwin
  • 102
  • 8
3
votes
2 answers

Dynamic Programming Solution for a Variant of Coin Exchange

I am practicing Dynamic Programming. I am focusing on the following variant of the coin exchange problem: Let S = [1, 2, 6, 12, 24, 48, 60] be a constant set of integer coin denominations. Let n be a positive integer amount of money attainable via…
Eduardo
  • 697
  • 8
  • 26
3
votes
4 answers

Representing an amount of money with specific bills

I want to write a function in Racket which takes an amount of money and a list of specific bill-values, and then returns a list with the amount of bills used of every type to make the given amount in total. For example (calc 415 (list 100 10 5 2 1))…
1
2
3
17 18