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

Coin Change Problem return coins used along with minimum coin value

import java.util.*; public class CoinChange { public static int coinChange(int[] coins, int amount) { // Create an array to store the minimum number of coins needed to make change for each amount int[] dp = new int[amount +…
Crimz
  • 3
  • 3
0
votes
1 answer

Coin Change Dynamic Programming Problem (limited supply of coins)

I'm trying to solve the coin change problem with the variation that the same coin can be used at most twice. I solved the problem where the coins are unlimited but I still don't quite understand how to do it in case of limited coins. function…
0
votes
1 answer

Why two seemingly similar implementations of the same DP algorithm differ?

I'm implementing a dynamic programming (DP) solution to an "unbounded knapsack"-family problem. To be more precise, the problem is to find all possible change for the given amount having a set of n coins (an infinite number of each kind of coin).…
0
votes
0 answers

Using tree recursion to solve coin change question

Given a positive integer change, a set of coins makes change for change if the sum of the values of the coins is change. We will use standard US Coin values: 1, 5, 10, 25. I was asked to solve this coin change question with recursion function…
Phyllis
  • 1
  • 2
0
votes
3 answers

How to find subsets from a set that product equals the target?

Let us say we have a list and target of: list: [1,2,3,4,5] and target: 20 and we want to find total combinations to reach this, with multiplication, which is: [1,4,5], [4,5], [2,5,2], [1,2,2,5] I did this code, but I can't seem to know how to remove…
0
votes
0 answers

Behaviour of Arraylist passed as parameter in Recursion

I am trying to solve a DSA problem for Minimum coin change,For that trying to print all the combinations of coins needed to make a certain amount. Below are two programs one uses String as a param and other one uses ArrayList. String one seems to…
0
votes
1 answer

Leetcode 322: Coin change recursive approach gives wrong answer

I'm trying to solve the famous coin change problem using the naive recursive solution (I'll use this as a blueprint before adding memoization or tabulation). You are given an integer array coins representing coins of different denominations and an…
Victor Cui
  • 1,393
  • 2
  • 15
  • 35
0
votes
1 answer

Print out and sort values inside LinkedList

I wrote a recursive backtracking algorithm for the so-called "Coin Change Problem". I store the coin values (int) in a self-written LinkedList ("ll") and each of those LinkedLists is stored inside one master LinkedList ("ll_total"). Now, when I try…
Mar
  • 43
  • 3
0
votes
0 answers

Coin Counter Math Issue - If statement wont accept corect values

Hi I am trying too create code that takes an amount like 1.35 and counts the minimum amount of coins needed to make change just out of coins, 5 quarters, and 1 dime. but my code has some interesting errors example 1.35 shows correct at 5 quarters…
0
votes
1 answer

decimal loop not printing the output in python. I'm trying to display minimum change coins for decimal values

def change(): paid = Decimal(input("Amount Paid: £")) change = Decimal(10) - Decimal(paid) #10-4.75 print ("Change due: £", Decimal(change)) print ("Hand the customer: ") denoms = map(Decimal, ('5.00', '2.00', '1.00',…
0
votes
1 answer

Find exact change project

I'm doing a lab for school to find the exact change. For example 126 is the input the answer would be 1 dollar 1 quarter 1 penny. grammar matters too. I can't get the pennies part to work. It seems to stop working after 104. Also, I'm sure there are…
0
votes
1 answer

When does the Greedy Algorithm for the Coin change making problem always fail/always optimal?

I understand how the greedy algorithm for the coin change problem works. I am just a bit confused on when the output is always optimal (when using the Greedy) and when the greedy will always fail. For example the US coin denominations are canonical…
King
  • 1
  • 1
0
votes
0 answers

Problem similar to Coin change problem with finite coins, but with intervallic coin values and fixed number of coins

I have been struggling to create an algorithm, for a problem where we get an array of n coins with their max values. A coin in the array can have a value between 0 and this max value. We want to determine ALL permutations of possible order of coins…
0
votes
4 answers

Python ATM program not working as intended

I'm trying to make an ATM-like program in Python. The idea is that the user inputs any amount of money and the minimum amount of bills (100, 50, 25, 10, 5) will be printed. So for example: Input: 258 expected output: "2 $100 Bills, 1 $50 Bill, 1 $5…
0
votes
6 answers

Algorithm or solution for selecting possible combinations of menu items within a budget

Using Java 8, I am trying to figure out an algorithm / proper solution to see how to store a List with buyable items within a certain allocated budget. Suppose, a Map which contains the following keys / values: Map
PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144