One Pager Cheat Sheet

  • The task is to find the minimum number of coins that add up to a given denomination amount using dynamic programming, with a given set of coins of different denominations and an infinite supply of each one.
  • This problem can be solved using an efficient dynamic programming algorithm to efficiently explore all possible combinations and find the one with a minimum number of coins.
  • Boldly dynamic programming is used to define an array matrix M, whose size is N*(amount+1) to store the intermediate results of the coin change problem.
  • The figure shows how the Matrix M is filled row by row, with each value in the cell equaling the minimum number of coins required to pay the amount, given the coin denomination for that row.
  • Write code to solve the coin change problem in O(NT) time, where inf is the highest value of the coin denominations and -1 is returned if no combination is possible.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT

Great job getting through this. Let's move on.

If you had any problems with this tutorial, check out the main forum thread here.