Skip to content

Commit

Permalink
Fixing stle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jagdish-15 committed Nov 9, 2024
1 parent 6152c10 commit 5d398d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ 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**:

- 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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/change/.approaches/intrduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand Down

0 comments on commit 5d398d0

Please sign in to comment.