Wednesday, December 20, 2017

Coin Change Problem with Memoization and DP by Cracking the Coding Interview Author Tutorial Recommendation

The key to the coin change problem is Dynamic programming coin change with and without the coin. Start from bottom up rather than largest denomination to small. 

This is another coin change problem tutorial we recommend. This one is by Cracking the Coding Interview (the bible of coding interview) author Gayle Laakmann Mcdowell. The explanation is crystal clear and very helpful. The only thing it didn't cover in depth is the idea of using a coin (reduce sum) and withholding a coin (not reducing the sum) while increasing the index to process the next coin. This is also a memoization and dynamic programming problem.

Previously we recommended Coin Change problem by O'Neill Code. That one uses a bottom up greedy approach to solve for smaller denominations. Then add the ways up as approaching bigger denominations.

Tutorial highlights

Visualize using a coin versus not using a coin

Gayle Laakmann Mcdowell helps visualize using a coin vs withholding a coin.

Visualize the need for memoization

Using 50 cents is equivalent to using two 25 cents. The same sub problem appears when the original problem is reduced. Amount is now 29 cents. If we don't use dynamic programming we will be repeating work. 
Hacker Rank tutorial video coin change problem
Other tutorials that cover the coin change problem include Geek for Geeks, Interview Cake (there are some pluses and minuses, the variable names are a bit hard to read, but the code has a python version!). Most sample codes are in JAVA.

1 comment:

  1. Good web site! I really love how it is simple on my eyes and the data are well written. I’m wondering how I could be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a nice day!


React UI, UI UX, Reactstrap React Bootstrap

React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid