The best video on this topic and this example. I understand DP much better after this video. Thank you so much!
@ChaitanyaPaiTechie9 жыл бұрын
Dynamic programming is now getting easy for me after watching your videos. Thank u for posting.
@MatticusF1nch9 жыл бұрын
All of your videos are nice and concise. Helping me a lot studying for an algorithms final. Keep 'em up!
@ericvantassell6809 Жыл бұрын
Amen to that. Many other youtubers take 20+ minutes on a less effective presentation
@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.
@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.
@YabeDayoo6 жыл бұрын
chicor2000 smart
@YabeDayoo6 жыл бұрын
chicor2000 3 years ago idk
@YabeDayoo6 жыл бұрын
IDC
@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.
@naveenchowdary79595 жыл бұрын
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
@shashanksagarjha28074 жыл бұрын
please check this playlist : kzbin.info/aero/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr
@lanar35285 жыл бұрын
You need to explain how you go to the optimal substructure for this problem, that's what I'm struggling with
@shubhamgoyal26229 жыл бұрын
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.
@rahilthakkar60074 жыл бұрын
thxx man it will save me an hour in examination...its jst amazing! truly grateful to you..
@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.
@qwarlock41262 жыл бұрын
You are brilliant.. simply elegantly brilliant
@AsadShahabuddin7 жыл бұрын
Really great explanation. Thanks a ton.
@keshavrastogi6859 жыл бұрын
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_bake27439 жыл бұрын
+keshav rastogi Thanks mate, your code is helped me!!!
@stith_pragya3 жыл бұрын
superb explanation and Thank You Tushar Sir....
@swadheenta.957VBTS3 ай бұрын
Nice explanation solved my doubt thank you 💜
@rishabh1993able9 жыл бұрын
awesome......I struggled a lot in this problem now it is clear.......thanks
@subhashreesahu6929 ай бұрын
so quick and understanding easy to grasp
@11m08 жыл бұрын
Oh, so this is kindda like the knapsack prob u did...really helpful to know...thx
@pre_ty_things3 жыл бұрын
I am not sure if we really need 2D Dp. I did in one memo[0] = 0; for (int i = 1; i = coins[j]) { memo[i] = Math.min(memo[i], 1 + memo[i-coins[j]]); } } } return memo[amount];
@ShivangiSingh-wc3gk7 жыл бұрын
I like this one more than the new one, you speak so fast in the newer version
@abhishekgupta43609 жыл бұрын
All of ur lectures are just awesome.. really great explanation to each of the dp problem.....
@cristianouzumaki24553 жыл бұрын
More appropriate title would say " infinite denominations of same coin available"
@joyshah_22 Жыл бұрын
Excellent explaination💯💯💯
@sharonbinto3 жыл бұрын
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
@siddharthshah7118 жыл бұрын
Such a lucid solution! Thanks a lot! :)
@anymatix4917 жыл бұрын
Thanks sir for the solution ,been finding a clearly understandable video for this..
@my3m4 жыл бұрын
So much better explained than AlgoExpert
@qandrea10155 жыл бұрын
If 1 it is not in the coins. Just initialize T properly: in the first row of T we put +inf if j < "the smallest coin" (coin[1] in my case, I added zero in coin[0]). And then we fill the fist row with T[0][j] = T[0][j-coins[1]]+1 coins.sort() for i in range(len(coins)): T.append([]) for j in range(amount+1): T[i].append(0) for j in range(1,amount+1): if j < coins[1]: T[0][j] = float("inf") T[0][0] = 0 for j in range(1,amount+1): if coins[1]
@BorisMediaProds9 жыл бұрын
I love you, thank you for this tutorial!
@gauravlagad13609 жыл бұрын
Very Good Video! I am preparing for Interviews right now, and this is simply the best explanation I have got till now :)
@5k4k1dhtp9 жыл бұрын
Great video, very concise and understandable.
@Sushil28745 жыл бұрын
You explain very nicely..!! Thank you..!!
@subodhjain82499 жыл бұрын
code for the lecture m=size of array n=sum :) int count( int S[], int m, int n ) { // table[i] will be storing the number of solutions for // value i. We need n+1 rows as the table is consturcted // in bottom up manner using the base case (n = 0) int table[n+1]; // Initialize all table values as 0 memset(table, 0, sizeof(table)); // Base case (If given value is 0) table[0] = 1; // Pick all coins one by one and update the table[] values // after the index greater than or equal to the value of the // picked coin for(int i=0; i
@ashleycole30549 жыл бұрын
awesome video.. keep doing such a great job...
@shrutiawasthi349 жыл бұрын
such a nice explanation .. Thanks tushar.. it helped a lot... Keep posting more .:)
@raghibmusarrat14719 жыл бұрын
You algorithm gives wrong answer for the following problem: COINS: 2,3,5 Sum: 7 Please tell how to tackle this. The answer it gives is 0
@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
@pragatitanwar16715 жыл бұрын
Awesome video!!
@yanivgardi90289 жыл бұрын
thanks Tushar. This post is very helpful.
@no_love_3686 жыл бұрын
Great work there!
@velramesh054 жыл бұрын
Good explanation sir, thank you.
@borisjurcaga5 жыл бұрын
Thank you. I solving very similar problem and this video was very helpful.
@mohammedsafwan44473 жыл бұрын
thanks bro very helpful :)
@VINODKollipara9 жыл бұрын
great lecture..Thank you for posting it
@deepdesai78598 жыл бұрын
u made my exam.. 👍👍this is very help full...
@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.
@dongyuchen86254 жыл бұрын
if there isn't $1 coin this wouldn't work right?
@DhirajKumar-jf1yu4 жыл бұрын
If you implement the same way what he explained, it won't work if there isn't $1, but he has implemented in different way in his GitHub link. Even I implemented my code same way he explained and it fails if it doesn't have $1.
@dongyuchen86254 жыл бұрын
@@DhirajKumar-jf1yu Thanks mate. I solved it by set the initial values in the table to [0,'inf','inf'...'inf'], only update the value when the index is bigger than the coin. When the coins can't match the total value the last element in the table would always be 'inf'. But Tushar's video do give us a great example.
@sadmansakib005 жыл бұрын
What if we weren't given the coin 1 ?
@harikrishna62334 жыл бұрын
Thanks a lot .. its very helpful
@sainathtallam92624 жыл бұрын
great tutorial
@kittyjain46823 жыл бұрын
@Tushar Roy - You just started with the solution without explaining why ? It's not going to help anyone if we have to memorize it without knowing y.
@rushabhshah4345 жыл бұрын
There is an error in 2-3rd line it should be min( T(i-1)(j)+1,T(i)(j-coin(i) ) Here logic is ...let me explain by example of the 6 in above table..now filling matrics we've 2 possiblity to get desired value either 6 is included or not if 6 is not included then we copy above's i.e. here 5's answer for that value of i If 6 is included then we've to add other coins accordingly for obtainig the desired value.Now,we check wether this ans. With 6 is optimal or not by checking it with above ans. I.e. here 5's ans. Which is already optimal uptill that 5 for j Ty !
@kiranwali41339 жыл бұрын
Thanks a Ton Tushar !!
@shivjeetsingh86669 жыл бұрын
Nice video lecture. please upload more concept of dynamic programming.I solved many problem of Hacker Rank. Thanku :)
@ankitdeshpandey8367 жыл бұрын
Awesome tutorial
@riyankpatel94104 жыл бұрын
Great sir🙏
@BRBallin110 ай бұрын
What about examples where 1 isn't a coin denomination? Then there is no "top" value to use
@user-rqyjdhueklaq8 жыл бұрын
sum = 14 number of coins 3 2 3 5 Your algorithm gives wrong solution
@youssifkhairy17258 жыл бұрын
You should Sort Numbers First
@Kasa997 жыл бұрын
no need to sort
@henryhardcore85845 жыл бұрын
This algorithm doesn't check if the sum is possible to add up. If we have coins 2, and sum = 10.
@saumya18578 жыл бұрын
awsome explanation :)
@chandan_prabhakar5 жыл бұрын
nice video gautam gambhir
@esmamouine24227 жыл бұрын
trop bien mr.tushar.
@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.
@shobhitranjan39573 жыл бұрын
The solution won't work if no denominations are possible.
@ShashankGupta_Shanki9 жыл бұрын
great explanation...:)
@boosan_m5 жыл бұрын
Am I missing something? 1. This solution seems to work only for coins with 1 in it [2,3,5] & 11 won't work 2. Github link has a different solution in it.
@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.
@hankesteveo9 жыл бұрын
I kept up for a minute. Very good.
@DeepakSharma-di2fd9 жыл бұрын
simply awesome
@anshumansrivastava81085 жыл бұрын
how to check here if the total sum is possible or not using denominations?
@nishanksoni71205 жыл бұрын
You never explained why this logic is working. And why we are going for DP and what dp approach we are using
@mymislife5 жыл бұрын
Helpful! Thank you!!
@arunabhhejib11364 жыл бұрын
Every time I see your video I get the solution but have no idea how to get there. It would be better if you start from recursion and then lead to finding an optimal substructure and so on.
@glennpavel48004 жыл бұрын
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
@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.
@parthhingu15257 жыл бұрын
excellent teaching😊
@ivandrofly9 ай бұрын
Finds min number of coin you will give as a change for example
@manojpandey75174 жыл бұрын
He says "yes we will use dynamic programming..." and directly jumps to fill the table out of nowhere. That's why I could never learn anything from him. A bad technique to teach DP. The first and foremost step must be finding the recursive solution. I don't know why a lot of people out there recommend Tushar's video. I tried to watch his videos with a fresh mind but every time I felt let down. Sorry, but I cannot say "awesome tutorial" if I didn't learn anything. This is the last attempt I'm here.
@tricktreat79412 жыл бұрын
His videos are not for people like you. Tushar is the smartest LeetCoder on KZbin. You need to reach a certain level before you can make use of his contents. When you do, you will realize why people recommend him.
@manojpandey75172 жыл бұрын
@@tricktreat7941 it isn't about being smartest. He's teaching and a teacher doesn't need to be smartest to teach well. All I'm saying that this isn't a good way of teaching dynamic programming. If you want to know what a better way can be, watch Aditya Verma's dp Playlist.
@manojpandey75172 жыл бұрын
Another user has also pointed out and suggested him to first explain what's tempting him to use dp.
@ucanhly11662 жыл бұрын
I think the best teacher of algorithm on yt is Abdul Bari but actually haven't a lot of videos of dp but I learn from him so much and I came here to understand how to fill the table =))
@yudiguzman89266 жыл бұрын
Great. Thank so much.
@vasanthanv61432 жыл бұрын
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 ???
@omarosmanov7275 жыл бұрын
How to actually print out all combinations of amount? Let us say for amount=4, coins=[1,2,3] need to print out: (1,1,1,1); (2,2); (1,1,2);(1,3)
@TheNayanava5 жыл бұрын
that should be fairly easy. just run a dfs. create a List> as your result. add the coin to the list and subtract that amount from the list before calling dfs recursively. once you hit 0, you can append that list to your result. Don't forget to do a res.add(new ArrayList(list)). else it will keep pointing to the same list. Now while backtracking you can remove that coin from the list and try adding a new coin as long as the value of the coin is not greater than the amount. Please see this solution will actually have O(n^n) time complexity.
@sheenamjindal67033 жыл бұрын
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,
@yanlingyang2567 жыл бұрын
how could you come up with such equation i wonder : )
@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
@MayankSingh_is_me4 жыл бұрын
for coins = [10, 50, 100, 200, 500, 1000] and total = 11, noobs wud get stucked. having coin of denomination "1" in the very beginning takes away some critical aspect making everything a happy case! @TusharRoy: can u comment?
@HarshaVardhan-kq1sv4 жыл бұрын
Excellent sir. I have a doubt sir if we have multiple solution then how sir. Ex - coins: 1 2 3 Total: 4 Then dp tables will be 0 1 2 3 4 1 0 1 2 3 4 2 0 1 1 2 2 3 0 1 1 1 2 As dp[3][4] is 2, where the 2 is coming from above one as well as the 2 is coming from dp[3][1] i.e (1,3) and (2,2) So how we can traverse as we have multiple solutions like this. Sir can you explain this please sir.
@rahuldevgupta45133 жыл бұрын
It feels as if I am cramming the solution
@allanmagalhaes82113 жыл бұрын
lol i guess i understood everything until the final minute when you ran coding with no pauses
@johnhammer86682 жыл бұрын
3:16 why go back coin value steps back? Why does this work?
@krishnamali66938 жыл бұрын
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 ?
@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.
@punitivetoe18193 жыл бұрын
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-]
@MiguelCarvajalIB144 жыл бұрын
You got column and rows reversed, it is a bit confusing...
@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
@mohammad-sm3zt5 жыл бұрын
thanks a lot Tushar
@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!
@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
@diegogusava8 жыл бұрын
Thanks Tushar!!!
@divyaanshu73879 жыл бұрын
In first column you wrote 0.But in the another example you used 1.What is correct way.And that should be 1 beaoz there is possibility not to give change.
@gunjanbarhaiya2976 жыл бұрын
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?