Skip to content

Commit 8848ed1

Browse files
authored
Docs: add Javadoc to CoinChange class and method (#7424)
* Fix: remove floating Javadoc comments causing compilation error * Docs: add Javadoc to CoinChange class and method * Style: apply clang-format to CoinChange.java
1 parent 783c96f commit 8848ed1

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@
66

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

9+
/**
10+
* The Coin Change problem finds the minimum number of coins needed
11+
* to make a given amount using a greedy approach.
12+
*
13+
* <p>Note: This greedy approach works optimally for standard coin systems
14+
* (like Indian currency), but may not work for all arbitrary coin sets.
15+
* For arbitrary denominations, dynamic programming is preferred.
16+
*
17+
* @see <a href="https://en.wikipedia.org/wiki/Change-making_problem">Change-making problem</a>
18+
*/
919
public final class CoinChange {
1020
private CoinChange() {
1121
}
12-
// Function to solve the coin change problem
22+
23+
/**
24+
* Returns the list of coins used to make the given amount
25+
* using a greedy algorithm with standard denominations.
26+
*
27+
* <p>Time Complexity: O(n log n) where n is the number of coin denominations
28+
* <p>Space Complexity: O(n)
29+
*
30+
* @param amount the total amount to make change for
31+
* @return list of coins used to make the amount
32+
*/
1333
public static ArrayList<Integer> coinChangeProblem(int amount) {
1434
// Define an array of coin denominations in descending order
1535
Integer[] coins = {1, 2, 5, 10, 20, 50, 100, 500, 2000};

0 commit comments

Comments
 (0)