Skip to content

Commit 2ee9eb9

Browse files
committed
Added 2 Base tests and 5 main tests for CoinChange Problem. Refactored the code and removed the Memoized approach as it was not necessary
1 parent 43e9ebc commit 2ee9eb9

File tree

1 file changed

+0
-25
lines changed

1 file changed

+0
-25
lines changed

Dynamic-Programming/CoinChange.js

-25
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,3 @@ export const change = (coins, amount) => {
1515
}
1616
return combinations[amount]
1717
}
18-
function minimumCoins (coins, amount) {
19-
// minimumCoins[i] will store the minimum coins needed for amount i
20-
const minimumCoins = new Array(amount + 1).fill(0)
21-
22-
minimumCoins[0] = 0
23-
24-
for (let i = 1; i < amount + 1; i++) {
25-
minimumCoins[i] = Number.MAX_SAFE_INTEGER
26-
}
27-
for (let i = 1; i < amount + 1; i++) {
28-
for (let j = 0; j < coins.length; j++) {
29-
const coin = coins[j]
30-
if (coin <= i) {
31-
const subRes = minimumCoins[i - coin]
32-
if (
33-
subRes !== Number.MAX_SAFE_INTEGER &&
34-
subRes + 1 < minimumCoins[i]
35-
) {
36-
minimumCoins[i] = subRes + 1
37-
}
38-
}
39-
}
40-
}
41-
return minimumCoins[amount]
42-
}

0 commit comments

Comments
 (0)