Skip to content

Commit 2dea910

Browse files
committed
Updating content.md of dynamic approach of chnage exercise
1 parent 39f0e69 commit 2dea910

File tree

1 file changed

+13
-13
lines changed
  • exercises/practice/change/.approaches/dynamic-programming

1 file changed

+13
-13
lines changed

exercises/practice/change/.approaches/dynamic-programming/content.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ It minimizes the number of coins needed by breaking down the problem into smalle
4444

4545
## Explanation
4646

47-
1. **Initialize Coins Usage Tracker**:
47+
### Initialize Coins Usage Tracker
4848

49-
- If the `grandTotal` is negative, an exception is thrown immediately.
50-
- We create a list `coinsUsed`, where each index `i` stores the most efficient combination of coins that sum up to the value `i`.
51-
- The list is initialized with an empty list at index `0`, as no coins are needed to achieve a total of zero.
49+
- If the `grandTotal` is negative, an exception is thrown immediately.
50+
- We create a list `coinsUsed`, where each index `i` stores the most efficient combination of coins that sum up to the value `i`.
51+
- The list is initialized with an empty list at index `0`, as no coins are needed to achieve a total of zero.
5252

53-
2. **Iterative Dynamic Programming**:
53+
### Iterative Dynamic Programming
5454

55-
- 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`.
56-
- 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).
57-
- 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.
55+
- 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`.
56+
- 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).
57+
- 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.
5858

59-
3. **Result**:
59+
### Result
6060

61-
- After processing all values up to `grandTotal`, the combination at `coinsUsed[grandTotal]` will represent the most efficient solution.
62-
- If no valid combination exists for `grandTotal`, an exception is thrown.
61+
- After processing all values up to `grandTotal`, the combination at `coinsUsed[grandTotal]` will represent the most efficient solution.
62+
- If no valid combination exists for `grandTotal`, an exception is thrown.
6363

6464
## Time and Space Complexity
6565

66-
- The time complexity of this approach is **O(n * m)**, where `n` is the `grandTotal` and `m` is the number of available coin denominations. This is because we iterate over all coin denominations for each amount up to `grandTotal`.
66+
The time complexity of this approach is **O(n * m)**, where `n` is the `grandTotal` and `m` is the number of available coin denominations. This is because we iterate over all coin denominations for each amount up to `grandTotal`.
6767

68-
- The space complexity is **O(n)** due to the list `coinsUsed`, which stores the most efficient coin combination for each total up to `grandTotal`.
68+
The space complexity is **O(n)** due to the list `coinsUsed`, which stores the most efficient coin combination for each total up to `grandTotal`.

0 commit comments

Comments
 (0)