MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / coinChange

Function coinChange

javascript/0322-coin-change.js:9–17  ·  view source on GitHub ↗
(coins, amount, coin = 0)

Source from the content-addressed store, hash-verified

7 * @return {number}
8 */
9var coinChange = (coins, amount, coin = 0) => {
10 const isBaseCase1 = amount === 0;
11 if (isBaseCase1) return 0;
12
13 const isBaseCase2 = !(coin < coins.length && 0 < amount);
14 if (isBaseCase2) return -1;
15
16 return dfs(coins, amount, coin); /* Time O(S^N) | Space O(N) */
17};
18
19var dfs = (coins, amount, coin) => {
20 let [max, minCost] = [amount / coins[coin], Infinity];

Callers 1

dfsFunction · 0.70

Calls 3

dfsFunction · 0.70
initMemoFunction · 0.70
initTabuFunction · 0.70

Tested by

no test coverage detected