Profile picture
Alvin ZablanFounder at Structy and React Formula | ex-Google

Counting Change Approach

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function, counting_change, that takes in an amount and a list of coins. The function should return the number of different ways it is possible to make change for the given amount using the coins.

You may reuse a coin as many times as necessary.

For example,

counting_change(4, [1,2,3]) -> 4

There are four different ways to make an amount of 4:

1. 1 + 1 + 1 + 1

2. 1 + 1 + 2

3. 1 + 3

4. 2 + 2

counting_change(4, [1, 2, 3]) # -> 4
counting_change(8, [1, 2, 3]) # -> 10
counting_change(24, [5, 7, 3]) # -> 5

If you need additional support taking these DSA skills and actually applying them, take Alvin's complete data structures and algorithms course on Structy. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use this link to get 20% off the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: https://www.linkedin.com/in/alvin-zablan-b73a92117/