Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@

// Problem Link : https://en.wikipedia.org/wiki/Change-making_problem

/**
* The Coin Change problem finds the minimum number of coins needed
* to make a given amount using a greedy approach.
*
* <p>Note: This greedy approach works optimally for standard coin systems
* (like Indian currency), but may not work for all arbitrary coin sets.
* For arbitrary denominations, dynamic programming is preferred.
*
* @see <a href="https://en.wikipedia.org/wiki/Change-making_problem">Change-making problem</a>
*/
public final class CoinChange {
private CoinChange() {
}
// Function to solve the coin change problem

/**
* Returns the list of coins used to make the given amount
* using a greedy algorithm with standard denominations.
*
* <p>Time Complexity: O(n log n) where n is the number of coin denominations
* <p>Space Complexity: O(n)
*
* @param amount the total amount to make change for
* @return list of coins used to make the amount
*/
public static ArrayList<Integer> coinChangeProblem(int amount) {
// Define an array of coin denominations in descending order
Integer[] coins = {1, 2, 5, 10, 20, 50, 100, 500, 2000};
Expand Down
Loading