Challenge: Create an Amount
This challenge will test your skills of writing efficient code using functions in JavaScript.
We'll cover the following
Problem statement
Given an array of coins
, write a function to compute the number of ways you can make that amount
using those coins.
Note: There is an unlimited number of each coin type available.
Input
-
an
amount
-
an array,
coins
, containing different coins (in cents )
Output
- The number of ways to get the
amount
using thecoins
available
Sample input
amount = 4
coins = [1,2,3]
Here’s the amount
all the coin values are given in cents ().
Sample output
4
How did we get this answer? Let’s look at the different ways:
-
,,,
-
,,
-
,
-
,
All of the above coin combinations sum to the amount
given.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.