Given a list of coin denominations and a total amount, determine the number of unique combinations that can make up that amount. You may assume that you have an unlimited number of each coin.
For example, if the coin denominations are [1, 2, 5]
and the amount is 5
, there are 4 unique combinations:
Your task is to implement a function coinChange(coins, amount)
(or equivalent in your language of choice) that returns the number of ways to combine the coins to reach the given amount. This problem can be approached using dynamic programming.
Hint: Use a table (or array) where each index represents an amount from 0
to amount
and build up the solution by iterating over the coin denominations.
Note: January 26 is celebrated as Australia Day. Think about how combinations and variety (like the many ways to celebrate) play a role in this problem.