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

Intuition for array in dynamic problem: coin change combinations

Coding Problem Link i have coded the brute-force recursion without any DP. public class coinChangeCombination { public static void main(String[] args){ int[] coins = {2, 3, 5, 6}; int target = 7; …
0
votes
2 answers

Project Euler #31

Problem Description: In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1×£1 + 1×50p…
paperbd
  • 153
  • 1
  • 11
0
votes
1 answer

How to count the coin change combinations only once?

I have an assignment to make a function that receives only an integer and a list of integers(can't add anything else). It should return the number of combinations from the list that sums to k, the order doesn't matter(The coin change problem). …
Help
  • 25
  • 3
0
votes
2 answers

Sublist into String Python

I have a little problem , I have this code and I need to convert the final print to a string, to be able to printthe final results in different lines and change the separator "," to a "+". If someone could help me to fix this I will be grateful…
0
votes
2 answers

Find the coin change (Greedy Algorithm) when coins are in decimals and returned amount in coins is larger then original return value

I need to find the number of coins that make a given value where coins are in decimals and there is a possibility that the algorithm will return more coins (money) because there is no way to return the exact value where the returned amount is close…
user3681563
  • 103
  • 2
  • 11
0
votes
0 answers

Kotlin Function to Return Exact Change

I am most likely the greenest greenhorn on this site. Currently in school for software development and finishing my first quarter. I'm working on a simple problem where I need to create a function that returns exact change (as the title says). For…
bgZAG
  • 1
  • 2
0
votes
2 answers

Coin change logic

Im stuck at this problem about the change of a vending machine (using 10ct, 20 ct, 50ct, 100ct and 200ct-coins.) So lets say coffee costs 40cts. The user throws in 2€ (labeled 200cts). Now im supposed to figure out how the change of 160cts is given…
QWERTYZ
  • 5
  • 1
0
votes
1 answer

Dynamic Programming Coin Change Problem - Print Coins Used Java

So I have the coin change problem figured out and I understand how it works and everything but I cant seem to figure out how to print out how many of each coin is used. For example with the amount of 12 and the coin array of 1, 5, and 10 I want the…
0
votes
0 answers

find if given pack of coins can make a given value - coin row problem

given array of coins (int) and an int n the function need to return true if there is atleast one solution to the coin-change problem. meaning: for array of ints> 0: [c(0) ,c(1) ,c(2) ,c(3) ,...... ,c(k)]. check if there is a solution for the…
0
votes
2 answers

Implementing minimal coin amount for change with memoization?

I'm practicing the concepts of Dynamic Programming (recursion is not my strong suit). I was wondering how my piece of code may be improved so that I can avoid a stack overflow. Anything helps, thanks! def coinFlipping(n): """ For n amount of…
0
votes
1 answer

Coin Change Greedy Algorithm Not Passing Test Case

I'm trying to solve the coin change problem where you use the fewest amounts of coins possible to make an amount. I'm trying to use the Greedy Approach - my algorithm sorts the coins array, starts with the biggest coin and uses it as many times as…
j.Doie
  • 91
  • 1
  • 6
0
votes
1 answer

Find the number of possible sums which add to N using (1,...,K)

I have the following problem to solve: given a number N and 1<=k<=N, count the number of possible sums of (1,...,k) which add to N. There may be equal factors (e.g. if N=3 and k=2, (1,1,1) is a valid sum), but permutations must not be counted (e.g.,…
Alan Evangelista
  • 2,888
  • 6
  • 35
  • 45
0
votes
1 answer

Changing total value using the lowest amount of coins, whilst excluding a specific coin, and return result as String

I am facing an issue with one of my assignments, where a small part of the assignment is writing method for the below description: A method that takes two values; the value to exchange, and the coin type to exclude, and then return the minimum…
ZaweeeZ
  • 41
  • 7
0
votes
2 answers

Change coins in Python with recursive / Why no work?

this my code. The task of changing coins. I need to get a list of lists, with exchange options. a = [] def coinChange(coins, amount, result=None): if result is None: result = [] if amount < 1 and sum(result) == 3: …
Harry
  • 39
  • 6
0
votes
1 answer

How do I add memoization to this recursive approach?

I was attempting to solve the coin change problem (https://leetcode.com/problems/coin-change) and have come up with the following recursive approach: class Solution { public int coinChange(int[] coins, int amount) { int[] min = new…