Skip to content

Instantly share code, notes, and snippets.

@benfletcher
Last active May 3, 2017 21:01
Show Gist options
  • Save benfletcher/741d48de6b36b79102a13f75a53b315e to your computer and use it in GitHub Desktop.
Save benfletcher/741d48de6b36b79102a13f75a53b315e to your computer and use it in GitHub Desktop.

Compute the number of unique change combinations possible.

You will be given:

  • an amount of money
  • an array of coin denominations
  • you have access to an unlimited number of each coin denomination

For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:

1+1+1+1
1+1+2
2+2

Don't count coins in a different order more than once:

1+1+2 == 2+1+1

Your function should take an amount to change and an array of unique denominations for the coins:

computeChange(4, [1,2])     // => 3
computeChange(10, [5,2,3])  // => 4
computeChange(11, [5,7])    // => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment