Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexzobi/59ca8369502a3c328c463903e847af5f to your computer and use it in GitHub Desktop.
Save alexzobi/59ca8369502a3c328c463903e847af5f to your computer and use it in GitHub Desktop.
coins - bottom-up
function change(n, coins){
let combos = new Array(n+1).fill(0);
combos[0]= 1;
for (let coin of coins){
for (let i=1; i<=n; i++){
if(i >= coin){
combos[i] += combos[i-coin]
}
}
console.log('coin', coin)
console.log('combos', combos)
}
return combos[n];
}
change(25, [1,5,10,25]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment