From 6152c100a88f280066afd36ae745f39e03b38dee Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Sat, 9 Nov 2024 23:19:55 +0530 Subject: [PATCH] Fixing style errors --- .../change/.approaches/dynamic-programming/content.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exercises/practice/change/.approaches/dynamic-programming/content.md b/exercises/practice/change/.approaches/dynamic-programming/content.md index 2f283a312..260e52e77 100644 --- a/exercises/practice/change/.approaches/dynamic-programming/content.md +++ b/exercises/practice/change/.approaches/dynamic-programming/content.md @@ -6,16 +6,19 @@ This approach ensures that we find the most efficient way to make change and han ## Explanation -1. **Initialize Coins Usage Tracker**: +1. **Initialize Coins Usage Tracker**: + - We create a list `coinsUsed`, where each index `i` stores the most efficient combination of coins that sum up to the value `i`. - The list is initialized with an empty list at index `0`, as no coins are needed to achieve a total of zero. -2. **Iterative Dynamic Programming**: +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). - 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**: +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.