Given coins of certain denominations and a total, how many minimum coins would you need to make this total. github.com/mission-peace/inte... github.com/mission-peace/inte...
Пікірлер: 259
@MatticusF1nch9 жыл бұрын
All of your videos are nice and concise. Helping me a lot studying for an algorithms final. Keep 'em up!
@ericvantassell68098 ай бұрын
Amen to that. Many other youtubers take 20+ minutes on a less effective presentation
@lanar35285 жыл бұрын
You need to explain how you go to the optimal substructure for this problem, that's what I'm struggling with
@ChaitanyaPaiTechie8 жыл бұрын
Dynamic programming is now getting easy for me after watching your videos. Thank u for posting.
@VikasGupta20148 жыл бұрын
In DP problems, please start with recursion so that we could understand why it was need of DP here. Anyway awsome tutorial. Thanks a lot.
@scabbage7 жыл бұрын
agree
@jasonng31946 жыл бұрын
www.geeksforgeeks.org/dynamic-programming-set-7-coin-change/ Here, they have explained why DP is better them recursion. Simply because you can avoid repeated sub problems. But don't look at their DP solution coz it is not for minimum coin change. But the concept is essentially the same.
@naveenchowdary79594 жыл бұрын
he do not kow
@jk973224 жыл бұрын
@Arun Gowda In place of Matrix operation just call the function with same argument can give you a recursion solutions . You can refer geeks for geeks website
@shashanksagarjha28073 жыл бұрын
please check this playlist : kzbin.info/aero/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr
@AsadShahabuddin7 жыл бұрын
Really great explanation. Thanks a ton.
@5k4k1dhtp9 жыл бұрын
Great video, very concise and understandable.
@siddharthshah7117 жыл бұрын
Such a lucid solution! Thanks a lot! :)
@BorisMediaProds9 жыл бұрын
I love you, thank you for this tutorial!
@marcello-63519 жыл бұрын
Kudos Tushar! How would you adapt the solution to a real case scenario where coin supply is not infinite? Do you have anything about it? Thanks!
@atabhatti9 жыл бұрын
Thanks for making this video. I do have a couple of suggestions for you that will help your audience substantially: 1. Explain why you chose to use dynamic programming vs. recursion vs. some other scheme. 2. Explain why you are doing the min and why each flow of information (either from above or from the left) exists. You explain the mechanics but not the structure of the solution so your video helps me understand how this technique works but does not give me any intuition into where else I might use this solution. 3. Contrast this problem from other similar problems. For example the problem to list the number of ways you can make change from a given denomination of coins for a certain amount. Otherwise, thanks a lot.
@22PARTHGUPTA189 жыл бұрын
+Tushar Roy If you can add separate videos explaining why, they will be of great help and will enable the concepts to get the logic stick. Else these things are very difficult to remember later.
@YabeDayoo5 жыл бұрын
chicor2000 smart
@YabeDayoo5 жыл бұрын
chicor2000 3 years ago idk
@YabeDayoo5 жыл бұрын
IDC
@ShivangiSingh-wc3gk7 жыл бұрын
I like this one more than the new one, you speak so fast in the newer version
@yanlingyang2566 жыл бұрын
how could you come up with such equation i wonder : )
@abhishekgupta43609 жыл бұрын
All of ur lectures are just awesome.. really great explanation to each of the dp problem.....
@11m07 жыл бұрын
Oh, so this is kindda like the knapsack prob u did...really helpful to know...thx
@mehulkumarnirala87697 жыл бұрын
what if sum =12 in the same example? i am getting segmentation fault
@anymatix4916 жыл бұрын
Thanks sir for the solution ,been finding a clearly understandable video for this..
@borisjurcaga5 жыл бұрын
Thank you. I solving very similar problem and this video was very helpful.
@92362617418 жыл бұрын
1 5 6 8 should always be in increasing order ? Do I need to sort it before applying in the matrix?
@marvelfan54444 жыл бұрын
Yes, please sort them, so as to build inital rows with step-by-step clarity, as you increase the number of allowed denominations, you understand the pattern that evolves and can get a generalized value for the logic
@atulmaini11329 жыл бұрын
how is the condition if a particular sum cannot be made with current coins in hand?eg if the min value of the coin present is 2 and sum is 3.
@shubhamgoyal26228 жыл бұрын
Until I watched these videos pertaining to the concept of dynamic programming, everything literally went overhead. Now I would safely say I'm getting in the realm of dynamic programming. Thank you.
@sahildhawan228 жыл бұрын
Plain awesome! Just 1 question: Here for 11, I understood until the part where we'll require 2 coins, but couldn't understand the steps that led to determining that the coins were of denomination of 5 and 6.
@vinzane14124 жыл бұрын
Since the last element, 2 (number of coins) has originated from the previous row and the coin[i-1] is 6, it is clear that the solution contains 6 and so traverse back to 6 steps now and you find 1 which has come from it's prev row which is 5, so we also have 5.
@punitivetoe18192 жыл бұрын
How did row for 6 denom val 11 come to 2? Ans. For each cell we want min. Until now min for that denomination is the [i-1][j] val ie that value could have been made by using denominations until i ie 6 excluding 6. Remember each row represents cumulative factor ie considering all coins until i not just i. So using denom 1,5 we can make 11 using 3 coins. Thats the first term of the min i-1,j The question now remains can u make up 11 including 6. If u include 6, remaining value is 11-6 ie 5. So copy the value of min coins using 6 and reaching val 5 which is [i][j-denom ie 6-]
@ashleycole30548 жыл бұрын
awesome video.. keep doing such a great job...
@VINODKollipara9 жыл бұрын
great lecture..Thank you for posting it
@rahilthakkar60073 жыл бұрын
thxx man it will save me an hour in examination...its jst amazing! truly grateful to you..
@no_love_3685 жыл бұрын
Great work there!
@sharonbinto2 жыл бұрын
Thank you so much tushar. Your explanation is really the best and when I tried to code with your explanation. It was very easy and finally when the output came. Really it builds my confidence that I can also code. Thanks for the video
@qwarlock41262 жыл бұрын
You are brilliant.. simply elegantly brilliant
@CoolDivya10009 жыл бұрын
Thanks a lot. It looks quite difficult before your explanation, but your logic is very simple . And please upload a video for Assembly line Scheduling using Dynamic programming. Thanks again.
@gauravlagad13608 жыл бұрын
Very Good Video! I am preparing for Interviews right now, and this is simply the best explanation I have got till now :)
@alexcui35007 жыл бұрын
Do you know how to solve this if negative coin and negative target are allowed?
@zaktv35957 жыл бұрын
do these coins have to be in increasing order? if so i dont see why we would need 2d array since we can simply divide the target by largest coin , then divide remainder by next largest coins and so on. that would give us the min number of coins..
@rishabh1993able9 жыл бұрын
awesome......I struggled a lot in this problem now it is clear.......thanks
@saini851939 жыл бұрын
what is logic behind going a[i-1] steps back..?plz explain!
@morgana_vi6 жыл бұрын
Because when you have found that it came from coin 6, it means to get 11 you have already included coin with denomination 6, so the remaining is 5 . Now you need to find which coins are included to get 5 for which you need to go to that column, nothing but going 6 steps back.
@anshumansrivastava81084 жыл бұрын
how to check here if the total sum is possible or not using denominations?
@mymislife5 жыл бұрын
Helpful! Thank you!!
@uphaardubey43497 жыл бұрын
how can we put in code to see what are actual coins to sum up total??
@saumya18578 жыл бұрын
awsome explanation :)
@ronakgupta74928 жыл бұрын
Hi Tushar by this approach i had to set the first row to Integer.MAX and then was able to run 120 test cases out of 180 in leetcode. I really liked the approch but test cases like [186,419,83,408] sum =6249 giving me 18 instead of 20 idk whats wrong as the code seems to work for every other cases. Please post here if you know where i could be wrong
@lakshlumba26938 жыл бұрын
Hi Tushar , Thanks for the great tutorial. Isn't the else part of this program in github should be like else { temp[i][j] = min ( temp[i][j-coins[i-1]] +1 , temp[i-1][j]) ; } instead of else { temp[i][j] = temp[i][j-coins[i-1]] + temp[i-1][j]; }
@durgeshmishra10504 жыл бұрын
@tushar Roy what if our coins arent in sorted ordder?
@kiranwali41338 жыл бұрын
Thanks a Ton Tushar !!
@subhashreesahu6923 ай бұрын
so quick and understanding easy to grasp
@dilipdiwakars8 жыл бұрын
for a coin 5 , why you are saying we have to go back 5 steps back and add 1 to it. Can you please explain. I am not getting that part
@tejasvigupta073 жыл бұрын
How do I fill the first row if I don't have 1 denomination coin? or is this solution requires us to have a coin of denomination of 1?
@ankitdeshpandey8366 жыл бұрын
Awesome tutorial
@123dxakash8 жыл бұрын
Thanks for the videos. They are very good. One question Whenever the total is not divisible by any of the coins then the algorithm fails. Can you please tell if this issue can be solved?
@123dxakash8 жыл бұрын
+Tushar Roy ok thanks for videos anyways one last question How can we find the subset of coins which makes total minimally?
@deepdesai78597 жыл бұрын
u made my exam.. 👍👍this is very help full...
@Sushil28744 жыл бұрын
You explain very nicely..!! Thank you..!!
@MatteoMircoli9 жыл бұрын
hi, I don't understand why : for(int i=0; i
@shrutiawasthi348 жыл бұрын
such a nice explanation .. Thanks tushar.. it helped a lot... Keep posting more .:)
@pragatitanwar16715 жыл бұрын
Awesome video!!
@krishnamali66937 жыл бұрын
Hello Tushar, Thanks for helping us all. I tried this algoritham on {2,3,5,7} set of coins with any total weight, it fails. So it is must to have coin of 1 in our set to get correct answer through this algo ?
@vasanthanv6143 Жыл бұрын
Hi , Great video , but can you please tell me why are we taking Integer.MAX_VALUE -1 for intialization in the first row and why not Integer.MAX_VALUE ???
@AyushRaj-pm1dz2 жыл бұрын
How will the initialization wrok if lets say coins[ ] = {2,4,6} ??? As in this example coins[0] was 1..therefore it worked... Can anyone explain the initilization part..?
@shelllu68883 жыл бұрын
I have watched 4 different types of Money change Dynamic Programming videos, this is so far the best, beating the lecture video from Coursera Algorithm course. If you wanna learn it, watch this first.
@VaibhavShewale4 жыл бұрын
well, why do i have different answer then?
@pranaysanam3 жыл бұрын
denominations [6,8,9] amount 7 what would be the table values? I mean for eg, take ways at index 7, according to the solution we get 1 but in reality how can you give change to 7 using which 1 coin???
@davidbarth807 жыл бұрын
Lost it at the formula! Anyone can help? Cheers
@keshavrastogi6858 жыл бұрын
We have to add one more condition in which we have to check that the row should be greater than 1 , then only we have to check the minimum of both . If we are in the first row , then we have to directly take dp[i][j-a[i]]+1. for(int i=1;i
@mister_bake27438 жыл бұрын
+keshav rastogi Thanks mate, your code is helped me!!!
@sadmansakib005 жыл бұрын
What if we weren't given the coin 1 ?
@jonathanlong27515 жыл бұрын
Thank you so much!.
@rianchannel92644 жыл бұрын
what if the number of coins are limited? can anyone explain me? or give me a link to another video?
@mrinalmandal9147 жыл бұрын
Thanks Tushar!!!
@ShashankGupta_Shanki9 жыл бұрын
great explanation...:)
@how2tech4035 жыл бұрын
can you explain intuition behind the solution??
@jg87425 жыл бұрын
dear sir . it would be helpful If you explain the problem with code also. As it is very difficult to code, although conceptually it is easy I was looking for an explaination like your trees playlist
@glennpavel48003 жыл бұрын
hi, idk if I understand wrong from 1 or position 6 value 5 , five positions back is 0 , like this 1-1 pos =4, -1 pos = 3 ... -5 = 0 not 1 has you show in minute 3:20 , or I'm doing something bad? thanks for your help
@yudiguzman89265 жыл бұрын
Great. Thank so much.
@yanivgardi90288 жыл бұрын
thanks Tushar. This post is very helpful.
@mohammedsafwan44472 жыл бұрын
thanks bro very helpful :)
@hankesteveo8 жыл бұрын
I kept up for a minute. Very good.
@gunjanbarhaiya2975 жыл бұрын
Sir the trick you give to deal with dynamic programming is superb! But i just wanna know how can i develop the logic or trick as you do?
@aditya2345674 жыл бұрын
practice!
@velramesh054 жыл бұрын
Good explanation sir, thank you.
@DeepakSharma-di2fd9 жыл бұрын
simply awesome
@DarlingMySweet6 жыл бұрын
I think of it like this: Say we want to put [2, 5, 3] into 7, and we've already figured out that there is 1 way to put [2, 5] into 7. To add 3 to the mix we just add the number of ways that [2, 5, 3] goes into 4. The logic is that since 7 - 3 = 4, any combos that have 3 in them will be with some coin mix that totals 4. So [2, 5] into 7 = 1 + [2, 5, 3] into 4 = 1, means that [2, 5, 3] into 7 = 2.
@shivjeetsingh86669 жыл бұрын
Nice video lecture. please upload more concept of dynamic programming.I solved many problem of Hacker Rank. Thanku :)
@weixing89857 жыл бұрын
Thank you!
@johnhammer86682 жыл бұрын
3:16 why go back coin value steps back? Why does this work?
@sheenamjindal67032 жыл бұрын
wondering if it really solves the problem by writing the core logic you provided in the video. I tried but it didnt work for me,
@hamicartoon4 жыл бұрын
Can't we solve this using window replacing
@XAngelsLifeX8 жыл бұрын
Спасибо за видео
@mingleizha88689 жыл бұрын
It is knapsack problem except you are trying to get the number of items!
@aziz94888 жыл бұрын
True, it's the same as the unbounded knapsack problem
@05.nguyenkhanhduy9 Жыл бұрын
i can asking you if not changing = total how to code ?
@jesanahammedovi90613 жыл бұрын
If we don't have $1 bill then what happen in 1st row?
@sanjeevshukla38219 жыл бұрын
i think we need a 0th row containing all 0's. so that if coin denomination starts from a number which is greater then the sum. then copy old value from top.
@fahadmohdshahid41108 жыл бұрын
We need to fill it by infinite(int_max) not by 0.
@harikrishna62334 жыл бұрын
Thanks a lot .. its very helpful
@yernartalgatuly42528 жыл бұрын
what is the difference between this problem and subset sum problem?
@yernartalgatuly42528 жыл бұрын
***** Understood. Thanks
@stith_pragya3 жыл бұрын
superb explanation and Thank You Tushar Sir....
@SUDHIRKUMAR-vh9pd7 жыл бұрын
hi Tushar...nice video.... what happens if there is no coin having value 1 ; ex total sum =10 coin ={3}
@islamtaison80518 жыл бұрын
عالنعمة انت شبح .. تسلم ^_^
@md.razaulhaquesubho47108 жыл бұрын
how can you solve this problem for {2,4,6} to make 8 ??
@123dxakash8 жыл бұрын
+Shuvo Opu just use the condition if(i==0) { if(j%coins[i]==0){ t[i][j]=j/coins[i];} else t[i][j]=0; }
@joyshah_227 ай бұрын
Excellent explaination💯💯💯
@ihashib5 жыл бұрын
Traced your code with the matrix you made, have a little problem, at min{T[i-1][j], 1+ T[i][j-coin[i]}, gonna consider that the 2d matrix has 0 as dummy index, so min{0, 1+ (0-1)}, so min will select, 0. So, T[1][1] is 0 not 1. If i don't consider 0 as dummy index, then it'll give error. Confused.
@sainathtallam92623 жыл бұрын
great tutorial
@prinzmukka9 жыл бұрын
Good one !!
@routhukishore76437 жыл бұрын
how it works in case of 2, 5, 6, 8 and total = 11 ?
@marouane556 жыл бұрын
you cant have 2,5,6,8 cents without 1 cent it is the base (2 cents doesn't make sense without 1)
@rabindrapatra71514 жыл бұрын
@@marouane55 if something is not working then we need to made assumption or base case.
@esmamouine24226 жыл бұрын
trop bien mr.tushar.
@rajamalakar75767 жыл бұрын
is it not necessary to sort the coins in asc .. please answer..
@wpavada32477 жыл бұрын
No it is not necessary
@HarishAmarnath4 жыл бұрын
yes it is necessary to sort, in dynamic programming way, we need to know the result of 1 to find the result of 5 hence it should be sorted first
@riyankpatel94103 жыл бұрын
Great sir🙏
@hackerexpert68197 жыл бұрын
what if there is no coin of denomination 1
@karansaxena44226 жыл бұрын
ide.geeksforgeeks.org/VivacD
@morgana_vi6 жыл бұрын
this gives a wrong answer then. I think that is why he made another video
@pratikgupta30895 жыл бұрын
then give a very large value to those cells where V