← Back to challenges

Coins Combinations

JavaScriptHardarraysnumberslogic

Instructions

Given an amount of money and an array of coins denominations, create a function that counts how many different ways you can make change with the given money.

Examples

coinsCombinations(4, [1, 2]) ➞ 3
// 1+1+1+1 = 4
// 1+1+2 = 4
// 2+2 = 4

coinsCombinations(10, [5, 2, 3]) ➞ 4

coinsCombinations(11, [5, 7]) ➞ 0

Notes

  • Order of coins does not matter (i.e. 1+1+2 == 2+1+1).
  • You have an infinite amount of coins.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.