diff --git a/exercises/practice/change/.approaches/dynamic-programming/content.md b/exercises/practice/change/.approaches/dynamic-programming/content.md index 260e52e77..cce152a0b 100644 --- a/exercises/practice/change/.approaches/dynamic-programming/content.md +++ b/exercises/practice/change/.approaches/dynamic-programming/content.md @@ -14,7 +14,7 @@ This approach ensures that we find the most efficient way to make change and han 2. **Iterative Dynamic Programming**: - For each value `i` from 1 to `grandTotal`, we explore all available coin denominations to find the best combination that can achieve the total `i`. - - For each coin, we check if it can be part of the solution (i.e., if `coin <= i` and `coinsUsed[i - coin]` is a valid combination). + - For each coin, we check if it can be part of the solution (i.e., if `coin <= i` and `coinsUsed[i - coin]` is a valid combination). - If so, we generate a new combination by adding the current coin to the solution for `i - coin`. We then compare the size of this new combination with the existing best combination and keep the one with fewer coins. 3. **Result**: @@ -22,7 +22,6 @@ This approach ensures that we find the most efficient way to make change and han - After processing all values up to `grandTotal`, the combination at `coinsUsed[grandTotal]` will represent the most efficient solution. - If no valid combination exists for `grandTotal`, an exception is thrown. - ```java import java.util.List; import java.util.ArrayList; @@ -77,7 +76,7 @@ class ChangeCalculator { - **Efficiency**: This approach is highly efficient in terms of minimizing the number of coins, but it might require significant memory for larger `grandTotal` values, as the space complexity grows linearly with `grandTotal`. -- **Alternative Approaches**: +- **Alternative Approaches**: - A **Greedy Approach** could be faster for some cases but does not always guarantee the minimum number of coins. - This dynamic programming approach is best when the goal is to guarantee the fewest coins possible, especially when no simple greedy solution exists. diff --git a/exercises/practice/change/.approaches/intrduction.md b/exercises/practice/change/.approaches/intrduction.md index 84531fad3..3834d706d 100644 --- a/exercises/practice/change/.approaches/intrduction.md +++ b/exercises/practice/change/.approaches/intrduction.md @@ -2,7 +2,7 @@ In the "Change Calculator" exercise, the goal is to determine the minimum number of coins needed to reach a given total using a specific set of coin denominations. This is a classic problem in dynamic programming, where efficient change-making is essential, especially when there are constraints on coin types or large totals. -### Problem Overview +## Problem Overview Given: @@ -11,13 +11,13 @@ Given: The solution should find the optimal combination of coins to match the total. If it's impossible to match the total exactly, the solution should indicate this by throwing an exception. -### Approach Overview +## Approach Overview Our solution uses a **dynamic programming approach**, where we systematically build up the optimal combinations for all totals from `0` up to the target amount (`grandTotal`). For each total, we track the fewest coins needed to make that total, reusing previous results to make the solution efficient. This approach ensures that we find the minimum number of coins required in a structured, repeatable way, avoiding the need for complex recursive calls or excessive backtracking. -### Key Features of the Approach +## Key Features of the Approach - **Efficiency**: By building solutions for each increment up to `grandTotal`, this approach minimizes redundant calculations. - **Flexibility**: Handles cases where exact change is impossible by checking at each step.