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

Function search

javascript/0518-coin-change-ii.js:129–145  ·  view source on GitHub ↗
(amount, coins, tabu)

Source from the content-addressed store, hash-verified

127};
128
129var search = (amount, coins, tabu) => {
130 for (let coin = 1; coin <= coins.length; coin++) {
131 /* Time O(N)*/
132 tabu[coin][0] = 1; /* Space O(N * AMOUNT) */
133
134 for (let _amount = 1; _amount <= amount; _amount++) {
135 /* Time O(AMOUNT) */
136 tabu[coin][_amount] = tabu[coin - 1][_amount];
137
138 const canUpdate = 0 <= _amount - coins[coin - 1];
139 if (!canUpdate) continue;
140
141 const val = tabu[coin][_amount - coins[coin - 1]];
142 tabu[coin][_amount] += val; /* Space O(N * AMOUNT) */
143 }
144 }
145};
146
147/**
148 * DP - Bottom Up

Callers 1

changeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected