Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created July 6, 2021 18:19
Show Gist options
  • Save Shaddyjr/9b26a4cc15c7bde2e603c83ac0085b90 to your computer and use it in GitHub Desktop.
Save Shaddyjr/9b26a4cc15c7bde2e603c83ac0085b90 to your computer and use it in GitHub Desktop.
// source: https://www.hackerrank.com/challenges/coin-change
// video: https://www.youtube.com/watch?v=b34GYbwwrJ8
function getWays(n, c) {
const store = new Array(n + 1).fill(0);
store[0] = 1;
for(const coin of c){
for(let total = coin; total < store.length; total++){
const remainder = total - coin;
store[total] += store[remainder];
}
}
return store[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment