FunctionRacerProblemsRace

Ways to Make Change

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

Given distinct coin values coins (each usable any number of times) and a target amount, return the number of different combinations of coins that add up to exactly amount. The order of coins does not matter, so 1+2 and 2+1 are the same combination. For amount = 0 the answer is 1.

Example 1

coins [1,2,5]
amount 5
returns 4

5, 2+2+1, 2+1+1+1 and 1+1+1+1+1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems