In this lesson, Alvin explores the strategy to solving the following interview problem:
Write a function min_change that takes in an amount and a list of coins. The function should return the minimum number of coins required to create the amount. You may use each coin as many times as necessary.
If it is not possible to create the amount, then return -1.
min_change(8, [1, 5, 4, 12]) # -> 2, because 4+4 is the minimum coins possible
min_change(13, [1, 9, 5, 14, 30]) # -> 5
min_change(23, [2, 5, 7]) # -> 4
min_change(102, [1, 5, 10, 25]) # -> 6
min_change(200, [1, 5, 10, 25]) # -> 8
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/