Created
November 1, 2019 10:58
-
-
Save norbornen/907ea7e14966bee96c3b686faba3f055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function possibleSums(coins, quantity) { | |
let arr = new Set(); | |
for (let i = 0, clen = coins.length; i < clen; i++) { | |
const coin = coins[i]; | |
const qty = quantity[i]; | |
const curr_sums = Array.from(arr); | |
const curr_coins = new Array(qty).fill().map((undefined, idx) => { | |
const n = coin * (idx + 1); | |
arr.add(n); | |
return n; | |
}); | |
for (const s of curr_sums) { | |
for (let j = 0, jlen = curr_coins.length; j < jlen; j++) { | |
arr.add(curr_coins[j] + s); | |
} | |
} | |
} | |
return arr.size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment