From 2ee9eb965bfe6e160b610cb638dd4288b50f9bf6 Mon Sep 17 00:00:00 2001 From: Mandy8055 Date: Fri, 13 Aug 2021 12:58:55 +0530 Subject: [PATCH] Added 2 Base tests and 5 main tests for CoinChange Problem. Refactored the code and removed the Memoized approach as it was not necessary --- Dynamic-Programming/CoinChange.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/Dynamic-Programming/CoinChange.js b/Dynamic-Programming/CoinChange.js index 254729e02..d320e20db 100644 --- a/Dynamic-Programming/CoinChange.js +++ b/Dynamic-Programming/CoinChange.js @@ -15,28 +15,3 @@ export const change = (coins, amount) => { } return combinations[amount] } -function minimumCoins (coins, amount) { - // minimumCoins[i] will store the minimum coins needed for amount i - const minimumCoins = new Array(amount + 1).fill(0) - - minimumCoins[0] = 0 - - for (let i = 1; i < amount + 1; i++) { - minimumCoins[i] = Number.MAX_SAFE_INTEGER - } - for (let i = 1; i < amount + 1; i++) { - for (let j = 0; j < coins.length; j++) { - const coin = coins[j] - if (coin <= i) { - const subRes = minimumCoins[i - coin] - if ( - subRes !== Number.MAX_SAFE_INTEGER && - subRes + 1 < minimumCoins[i] - ) { - minimumCoins[i] = subRes + 1 - } - } - } - } - return minimumCoins[amount] -}