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
3
votes
1 answer

Smallest monetary amount that can be obtained using only coins of specified denominations that exceeds a threshold

In other words, given a set of n positive integers A and a threshold B, I want to find the smallest C so that: C > B C = A[1] * k[1] + A[2] * k[2] + ... + A[n] * k[n], k[i] are integers >= 0 As an example if A = { 6, 11, 16 } then the values we…
3
votes
3 answers

Find all combinations of a given set of integers summing up to a given sum

I am looking for an answer to the following problem. Given a set of integers (no duplicates) and a sum, find all possible combinations of the set's elements summing up to the sum. Solutions order does not matter (solutions {2, 2, 3} and {3, 2 ,2}…
Dzik
  • 41
  • 1
  • 5
3
votes
5 answers

Coin Change, just can't get it right

Hello i'm trying to create an algorythm that finds out how many ways i can get change back. But i just can't get the implemtation right, i keep getting 4 where i should get 6 and i just can't see why. This is my implementation in C#, it is create…
Androme
  • 2,399
  • 4
  • 43
  • 82
3
votes
2 answers

Twist on coin changing (minimize array of weights)

I'm building an app to be used for a workout with less than 10 different weights. For example: the workout might call for weights of {30,40,45,50,55,65,70,80}. Now it would be nice for the user to not have to determine how many 45 lb weights, 35 lb…
3
votes
2 answers

JavaScript - What's wrong with this coin change algorithm

I'm trying to use the greedy algorithm for calculating the minimum number of coins needed to reach an amount in JavaScript The return result will be an array consisting of the number of coins at each level I decided to make a function that would…
user5680735
  • 703
  • 2
  • 7
  • 21
3
votes
1 answer

Coin change using dynamic programming

I've been working on coin change problem using dynamic programming. I've tried to make an array fin[] which contains the minimum number of coins required for that index and then print it. I've written a code which I think should give correct output…
G.tan
  • 39
  • 4
3
votes
1 answer

Prolog : coin change

I am new to prolog, trying to solve this classic coin change problem. change(M,P,N,D) with formula that M>=0 and M = P+5*N+10*D here is my approach change(M,P,N,D) :- M is P+5*N+10*D, P is M - (5*N+10*10). couple of test-cases …
boxy
  • 139
  • 1
  • 7
3
votes
1 answer

DP Coin Change Explanation

Coin Change is a pretty popular problem which asks how many ways you can get to a sum of N cents using coins (C[0], C[1]...C[K-1]). The DP solution is to use the method s(N, K) = s(N, K-1) + s(N-C[K-1], K), where s(N,K) is the amount of ways to…
arilato
  • 33
  • 2
3
votes
2 answers

Java recursive coin change attempt

I'm trying the java coin change problem to enumerate all possible sets of change to be given for n. My logic follows as such: while n >= denom m { array[]+= denom m n-= denom m } list.add[array[]] return coinChanger(++denom) My code: public…
user3871
  • 12,432
  • 33
  • 128
  • 268
2
votes
3 answers

How to avoid duplicating the ArrayList on every recursive call

I have been trying to solve this leetcode question Combination Sum Given an array of distinct integers candidates and a target integer, >return a list of all unique combinations of candidates where the >chosen numbers sum to target. You may return…
2
votes
0 answers

What is the key difference between Combination Sum IV and No. of ways to make coin change problem?

Combination Sum Given an array of distinct integer nums and a target integer target, return the number of possible combinations that add up to the target. Input: nums = [1,2,3], target = 4 Output: 7 Explanation: The possible combination ways…
2
votes
0 answers

Recursive backtracking algorithm for the 'coin change problem'

I'm trying to solve the "Coin Change Problem" by implementing a recursive backtracking algorithm which will analyze all possible outcomes and show the optimal combination of coins. Unfortunately, I have no idea how I can compare the different…
2
votes
1 answer

Identifying when greedy method gives optimum solution

I was looking at this problem on leetcode https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/description/ The hints tell us to follow a greedy approach where we convert the time difference to minutes and pick the largest…
2
votes
2 answers

How can I add limited coins to the coin change problem? (Bottom-up - Dynamic programming)

I am new to dynamic programming (and C++ but I have more experience, some things are still unknown to me). How can I add LIMITED COINS to the coin change problem (see my code below - is a bit messy but I'm still working on it). I have a variable…
Alin M.
  • 33
  • 4
2
votes
1 answer

recursive coin change problem - count permutations

Given a list of coins and a positive integer n>0 I need to find the number of permutations which sum up to n. Each coin on the list can be used many times. for example - given the following list: lst = [1,3,4] and n=4, the function should return 4:…
user429400
  • 3,145
  • 12
  • 49
  • 68
1 2
3
17 18