On this Martin Luther King Jr. Day, we celebrate equality and perseverance. In the spirit of forging new paths, your task is to determine the number of ways to make change for a given amount using a set of coin denominations. This is a classic dynamic programming problem where each coin can be used an unlimited number of times.
Given an integer amount
and an array of integers coins
representing coin denominations, write a function that returns the number of distinct ways to combine the coins to sum up to amount
.
Example:
For amount = 5
and coins = [1, 2, 5]
, the output should be 4
because there are four ways:
amount
using any combination of the coins provided.The starter code includes a function signature for each of the following languages. Complete the implementation accordingly.
Happy coding and have a reflective Martin Luther King Jr. Day!