<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1537145424390636349</id><updated>2012-02-16T18:43:24.053-08:00</updated><category term='coin denomination problem'/><category term='google interview question'/><category term='google interview'/><title type='text'>My Google Interview</title><subtitle type='html'>My interview process as of now with Google</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cmonkeyfreeware.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1537145424390636349/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cmonkeyfreeware.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Conflixious</name><uri>http://www.blogger.com/profile/15281491925810334708</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1537145424390636349.post-2211331982936615950</id><published>2008-02-27T08:45:00.000-08:00</published><updated>2008-02-27T10:16:11.612-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google interview question'/><category scheme='http://www.blogger.com/atom/ns#' term='coin denomination problem'/><category scheme='http://www.blogger.com/atom/ns#' term='google interview'/><title type='text'>Coin Denomination Problem</title><content type='html'>The coin denomination problem (also known as the coin changing problem) is usually given as a demonstration for the uses of dynamic programming. It is also known to have been given as an interview question by big companies such as &lt;a href="http://www.google.com/"&gt;Google&lt;/a&gt; and &lt;a href="http://www.microsoft.com/"&gt;Microsoft&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The coin denomination problem is as follows: given a number which needs to be broken down into change (such as 24$), and a set of coins (or bills) or different values (such as 10$, 8$, 5$, 2$, and 1$ bills) what is the minimum number of bills needed which will add up to make the number.&lt;br /&gt;&lt;br /&gt;Since I am currently in the interview process with Google, I was searching for the type of questions on the internet, which is where I was first introduced to this problem. The author of one post I found &lt;a href="http://haroonsaeed.wordpress.com/2006/07/17/google-phone-interview-part-1-2/"&gt;(here)&lt;/a&gt;   who described his own phone interview with Google, said that the interviewer had asked him to give a solution to this problem, which he said he had stated in another blog post &lt;a href="http://haroonsaeed.wordpress.com/2006/06/06/coin-denomination-problem/"&gt;(here)&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But the solution that I had found was not recursive, the way it should be to demonstrate the use of dynamic programming in this case. I went ahead and wrote my own solution to this problem, in &lt;a href="http://www.python.org/"&gt;Python&lt;/a&gt;, a language I love (also freely available for windows).&lt;br /&gt;&lt;br /&gt;The code:&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;def CoinDenomination(value,coinArray):&lt;br /&gt;  if value == 0:&lt;br /&gt;      return [0,[]]&lt;br /&gt;    &lt;br /&gt;  if value &amp;lt; 0:&lt;br /&gt;      return [100000000,[]]&lt;br /&gt;    &lt;br /&gt;  minval = 100000&lt;br /&gt;  minind = len(coinArray)+1&lt;br /&gt;&lt;br /&gt;  for i in range(len(coinArray)):&lt;br /&gt;      retVal = CheckLeast(value-coinArray[i],coinArray)&lt;br /&gt;      if temp[0] &amp;lt; minval:&lt;br /&gt;          minval = retVal[0]&lt;br /&gt;          minind = i&lt;br /&gt;          coins = retVal[1]&lt;br /&gt;  coins.append(coinArray[minind])&lt;br /&gt;  return [1 + minval,coins]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__=="__main__":&lt;br /&gt;  retVal = CoinDenomination(24,[10,8,5,2,1])&lt;br /&gt;  print "Number of coins:\t",retVal[0]&lt;br /&gt;  print "Coins:\t\t\t",retVal[1]&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;It can be shown that this solution will always produce the optimal result (the least number of coins) whereas the greedy algorithm will always be faster than this solution. It is meant to demonstrate the power of dynamic programming and is a good exercise to try.&lt;br /&gt;&lt;br /&gt;Please feel free to publish your comments and questions below, I would be happy to help clarifying this if I can.&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1537145424390636349-2211331982936615950?l=cmonkeyfreeware.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cmonkeyfreeware.blogspot.com/feeds/2211331982936615950/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1537145424390636349&amp;postID=2211331982936615950' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1537145424390636349/posts/default/2211331982936615950'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1537145424390636349/posts/default/2211331982936615950'/><link rel='alternate' type='text/html' href='http://cmonkeyfreeware.blogspot.com/2008/02/coin-denomination-problem.html' title='Coin Denomination Problem'/><author><name>Conflixious</name><uri>http://www.blogger.com/profile/15281491925810334708</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
