Coin Change (LeetCode 322) | Full solution with beautiful diagrams and visuals | Simplified

  Рет қаралды 36,901

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 109
@boisaulit
@boisaulit 8 ай бұрын
Looked at neetcode's solution 3 times and didn't undertand it. Here I understand it the first time. Thank you!
@kartikforwork
@kartikforwork 7 ай бұрын
because he explain top down approach
@maninform3523
@maninform3523 5 ай бұрын
@@kartikforworkhe did bottom up also but his was too complicated to me
@AndyBnq
@AndyBnq 5 ай бұрын
True, his explanation is better than neetcode's for this problem and several others.
@SumanthKumar-ei1qp
@SumanthKumar-ei1qp Ай бұрын
The amount of clarity you had in your explanation is truly amazing!!
@codeforfreedom
@codeforfreedom Жыл бұрын
Gotcha, you finally made me understand that. After looking 3 different other videos and still was completely lost, thank you.
@ellenstuder4269
@ellenstuder4269 8 ай бұрын
like everyone else, this was the first explanation of this problem (and dynamic programming in general) that made any sense to me. thank you!!
@krrishh7
@krrishh7 5 ай бұрын
Nice explanation of the concept. Keep doing more such videos. ❤ However, just wanted to add a small detail here (in favour of others checking as well). It would be good if we could also initialise minCoinsDp[0] to 0 explicitly. As to reach amount 0, fewest number of coins is 0. Since its java code, I think it gets initialised automatically to 0, but for other primitive languages like c,c++ we need an initialiser and the loop in the example code is only running from i=1 (skipping 0). vector minCoinsDp(amount+1, INT_MAX); // default initialise all to INT_MAX minCoinsDp[0]=0; // special case If the code can be adjusted as above, all such ambiguity can be cleared.
@yomamasofat413
@yomamasofat413 3 ай бұрын
ikr? In javascript it's initialized to NaN
@pulkitjain5326
@pulkitjain5326 Ай бұрын
Absolutely Amazing Explanation, one & only on KZbin, MARK MY WORDS!!
@whiletrue1-wb6xf
@whiletrue1-wb6xf 3 ай бұрын
Listen, your explanation for this f**king question is the best online! Let's put aside the fact that you'll never need this in a real job, but for job interviews, this specific explanation is the best-much better than Neetcode
@anirudhakrishna6891
@anirudhakrishna6891 Ай бұрын
Amazing visualisation of the problem which helped me clearly understand the solution. Please continue doing your explanation with visualisations, they're extremely helpful
@duyviet5801
@duyviet5801 Жыл бұрын
I was so happy whenever I search a problem on Leetcode and find your video !
@huaqian3654
@huaqian3654 Жыл бұрын
Best explanation ever! I was really struggling with this one. Big thank-you to you sir!
@maharshikongari1107
@maharshikongari1107 3 ай бұрын
Gone through so many other video solutions but understood nothing. This is the best explanation ever for this question!!
@amansahil2725
@amansahil2725 5 ай бұрын
Dude you deserve more subscribers Wonderful explanation
@sathviku-s6p
@sathviku-s6p 10 ай бұрын
underated youtuber , u deserve views in millions brother
@parth2497
@parth2497 Жыл бұрын
Cleanest solution I could find for this problem. Thank you !
@nikoo28
@nikoo28 Жыл бұрын
Great to hear!
@mdshahidansari9126
@mdshahidansari9126 2 ай бұрын
Your way of explaining is excellent sir..
@nandhakumarkr3147
@nandhakumarkr3147 8 ай бұрын
Great intention and good patience in explaining the approach. Kudos 🎉
@nikoo28
@nikoo28 8 ай бұрын
thanks for the support..will keep making more videos.
@pramodca1750
@pramodca1750 Ай бұрын
Thanks Nikhil, well explained. I felt quick discussion of how code works with the test data would have been more helpful
@preetiupadhyay8760
@preetiupadhyay8760 2 ай бұрын
Thank you so much for explaining the concept .
@_RohitKasture
@_RohitKasture Ай бұрын
Great explanation, thank you very much for making DP so easy.
@ashok2089
@ashok2089 3 ай бұрын
Great explanation with amazing clear drawings. Thanks.
@ivandrofly
@ivandrofly 6 ай бұрын
Fully understand this problem now- I would say the stairs claiming is also a good one to check if you stuck here
@nikoo28
@nikoo28 6 ай бұрын
Yes, that is a similar one
@vanaparthibullisiva5739
@vanaparthibullisiva5739 4 ай бұрын
Sir , I started watching your lecture series. I am able to understand very well but sometimes it is bit difficult to understand the coding part even though we understood the theory. Sir ,no one can beat u in the explanation of the theory. Spend some more time to explain code. It is reallly useful for us..I suggested my friends to watch this series..very useful series I say.❤
@nikoo28
@nikoo28 3 ай бұрын
the thing is that today you have a lot of GPTs that can write the code for you. writing code in any language is no longer a challenge in my opinion. However, problem solving is and will always be the most important aspect. If you are understanding the solution correctly step by step, you will be able to write the code eventually. It is just a matter of time. To get the best learning, I would highly encourage you to write the code yourself, do not copy the provided code. :) All the very best for your goals!!
@yashthakur5712
@yashthakur5712 10 ай бұрын
Finally understood the code crystal clear
@vivekkumaryadav9862
@vivekkumaryadav9862 Жыл бұрын
A big Thanks to you sir...bht better way se apne explain kiya..
@ramuwilliamson345
@ramuwilliamson345 5 күн бұрын
Good explanation.
@Amarsri19
@Amarsri19 Жыл бұрын
Thanks for the visualization which brings more clarity.
@nikoo28
@nikoo28 11 ай бұрын
yep, visuals are easy to remember.
@bishwashkumarsah171
@bishwashkumarsah171 2 жыл бұрын
Your explanation is awesome sir.. but during that dry run code i was little confused...i was expecting u to tell about the for loop using some dry run....That was just my opinion..
@nikoo28
@nikoo28 2 жыл бұрын
I understand...but I realized that the video already went too long, going over each step in the code would take another 10 minutes. If you follow the logic as explained, writing the for loop should not be tricky at all. What part of the loop are you facing a problem with? I can elaborate more as needed :)
@anniamatthews6803
@anniamatthews6803 Жыл бұрын
@@nikoo28 could you please explain the loop where you look through the coins and what exactly you are doing? I'm a little new to DP and I understand the solution but the implementation is a little fuzzy.
@nikoo2805
@nikoo2805 Жыл бұрын
What part of the loop are you facing a problem with?
@dhineshbabu9376
@dhineshbabu9376 11 ай бұрын
👯 Finally, a video to understand this method 🥳🥳🥳
@ИгорьКабаков-з4м
@ИгорьКабаков-з4м Жыл бұрын
Respect, i love iterative explanations.
@bookflexapp4804
@bookflexapp4804 11 ай бұрын
Best explanation ever! Thank you!
@ayushmehta0113
@ayushmehta0113 8 ай бұрын
explanation was 10/10 but you should once explain the code also using the same example line by line
@nikoo28
@nikoo28 8 ай бұрын
it is hard to explain line by line...everyone has a different coding style. If you understand the explanation, you should try to write the solution on your own.
@KurhePratyushAjay
@KurhePratyushAjay 5 ай бұрын
Thank you so much sir for such nice explainations.
@rajeshkannan8608
@rajeshkannan8608 Ай бұрын
i can't understand the if condition inside each coin for loop at first we chaeck whether the coin is less than the amount after that ?
@mamtayadav6195
@mamtayadav6195 5 ай бұрын
Really Good Explanation! Thankyou.
@vcs649
@vcs649 7 ай бұрын
fantastic intuition
@sugandhabhandari4399
@sugandhabhandari4399 10 күн бұрын
Nailed it!
@arpitrathore354
@arpitrathore354 Жыл бұрын
Can we solve this problem using 2-D DP by taking two changing variables length of array and amount????
@nikoo28
@nikoo28 Жыл бұрын
try outlining a pseudo code/algorithm
@ark178
@ark178 3 ай бұрын
yes, it can be solved. And it is straightforward If you write the recursive code first then you can memoize it or write the bottom up using the recurrence.
@Rob-J-BJJ
@Rob-J-BJJ Жыл бұрын
great explanationn my brother just wish you would've gone through the if condition you have in the last part, because I know it gets the min, but I wanted to see it explained how
@nikoo28
@nikoo28 Жыл бұрын
that is just comparison to get the minimum number. What are you struggling with?
@cagarwal
@cagarwal Жыл бұрын
I struggled for the whole day to be able to solve this problem. I could write the code by myself after watching how to fill in the array. One request - Can you make a video of solving the same problem using recursion?
@nikoo28
@nikoo28 Жыл бұрын
i generally tried to avoid recursion. It is very very confusing...also every recursive problem can be solved iteratively. :)
@harshitkumar8988
@harshitkumar8988 10 ай бұрын
@@nikoo28 No Sir please make a video on recursion your teaching level is just wow understand all dp problem but unable to understand a recursion its request sir to make video on it.
@nikoo28
@nikoo28 10 ай бұрын
@@harshitkumar8988 Why do you want to solve it using recursion?
@harshitkumar8988
@harshitkumar8988 10 ай бұрын
@@nikoo28 Sir because i want from brute force to space optimization and tbh i didn't understand the concept of recursion i have solve approx 30 to 35 question on recursion but i didn't get it and the way you solve this problem is phenomenon . So if u use some sort of recursion explanation in between the lecture . That will be great
@tamils12345
@tamils12345 7 ай бұрын
Hello, Can you share your studio setup ? what are the tools you use for drawing, editing?
@nikoo28
@nikoo28 7 ай бұрын
Sure..I can elaborate more..but here was a sneak peek: kzbin.infoh2oCQmwvv94?feature=share
@Hulkuuu
@Hulkuuu 2 ай бұрын
Better if explained the IF conditon inside for loop 🙂
@Chriscs7
@Chriscs7 6 ай бұрын
Can you write a code that finds the minimum number of coins and also prints the actual coins used ?
@saikiran1426
@saikiran1426 2 ай бұрын
Make videos on backtracking plz 😊
@divypareek8230
@divypareek8230 6 ай бұрын
great video
@dineshkm7832
@dineshkm7832 2 ай бұрын
Thanks
@prashikmanwar2109
@prashikmanwar2109 10 ай бұрын
Beautiful explanation bhaii..!!
@nikoo28
@nikoo28 10 ай бұрын
It's my pleasure
@pandeyshashidhar
@pandeyshashidhar 10 ай бұрын
Thank You sooooooooooooo much
@MadpolygonDEV
@MadpolygonDEV Жыл бұрын
What would a brute force solution look like? Having a hard time visualising a bruteforce solution
@nikoo28
@nikoo28 Жыл бұрын
a brute force approach would involve generating all possible combinations of coins to find the minimum number of coins needed to make up the target amount. public int coinChange(int[] coins, int amount) { int result = backtrack(coins, amount); return (result == Integer.MAX_VALUE) ? -1 : result; } private int backtrack(int[] coins, int remainingAmount) { if (remainingAmount == 0) { return 0; } if (remainingAmount < 0) { return Integer.MAX_VALUE; // Return a large value to indicate invalid solution } int minCoins = Integer.MAX_VALUE; for (int coin : coins) { int subproblemResult = backtrack(coins, remainingAmount - coin); minCoins = Math.min(minCoins, subproblemResult + 1); } return minCoins; }
@susanjoshi5948
@susanjoshi5948 3 ай бұрын
aap nahi hote toh hamara kya hota? :D Thank you sir.
@HistoryHouse45
@HistoryHouse45 Жыл бұрын
sir could you please explain word break problem
@nikoo28
@nikoo28 Жыл бұрын
i have that problem in my pipeline of videos. Will add it soon
@yashthakur5712
@yashthakur5712 10 ай бұрын
Sir the explanation was excellent but pls explain the code because I am not able to understand that why are we writing as the code is.
@nikoo28
@nikoo28 9 ай бұрын
what part are you facing a problem with?
@shubhammanecr7
@shubhammanecr7 Жыл бұрын
Thanks for posting!
@nikoo28
@nikoo28 Жыл бұрын
You're welcome
@whyybhav
@whyybhav Ай бұрын
why not going via memoization?
@nikoo28
@nikoo28 Ай бұрын
memoization simply means to reuse the results. That is exactly what we are doing. What approach do you have in mind?
@whyybhav
@whyybhav Ай бұрын
@@nikoo28 It wasn't intended other way, I just meant the approach which a person new to dp shall follow the memoization way post recursive solution in order to practice better , Directly explaining top down makes it a little hard Personal opinion
@ganeshktvb9234
@ganeshktvb9234 10 ай бұрын
Sir , im struggling to come up with dp solutions for a questions.so initially im solving with recursion and then memoizing and then converting it into dp. Is it ok or shoul i change my approach ?❤
@nikoo28
@nikoo28 9 ай бұрын
it is a very good approach indeed if you can think with all different methods. Will often lead you to the best choice. Your approach is correct. With practice you will be able to identify patterns and come up with solutions naturally. All the very best.
@ganeshktvb9234
@ganeshktvb9234 9 ай бұрын
@@nikoo28 thanks for reply sir❤️
@SivaSiva-wi2q
@SivaSiva-wi2q 3 ай бұрын
cant understand the logic u coded in the code...please explain that too in step by step
@sonofgod00
@sonofgod00 4 ай бұрын
thanks bhai
@mmm-ie5ws
@mmm-ie5ws 11 ай бұрын
the code part which is the most important part isnt explained well at all.
@nikoo28
@nikoo28 11 ай бұрын
Sorry if you felt that way...but I want to focus my channel on understanding the problem rather than writing code. I believe that if you have good problem solving skills, writing code is very trivial. There are a lot more channels who do a better job at writing the code :)
@ankitsrivastava2994
@ankitsrivastava2994 8 ай бұрын
​@@nikoo28means we should look other's solution instead so rude you are
@nikoo28
@nikoo28 8 ай бұрын
Always remember that languages will continue to change and evolve with time. The concept and the logic will remain forever the same. :) So, in order to become a better coder, I would highly recommend you to try writing the code on your own. 😃 If you are still interested to know how the code is working, use a debugger and iterate through the values. This way you will always be a better leaner.
@GopiKrishnasWorld
@GopiKrishnasWorld 7 ай бұрын
Thanks!
@nikoo28
@nikoo28 7 ай бұрын
Thanks for the support 😄
@syedaafreen1075
@syedaafreen1075 Жыл бұрын
Amazing
@ravilalachinnaraghavulu8207
@ravilalachinnaraghavulu8207 Жыл бұрын
Coine piker gurunchi app lo vache nebaru details anga tamobola
@OusmanBah-f8v
@OusmanBah-f8v 3 ай бұрын
When bro explains something it sticks forever.
@shwetathakare1556
@shwetathakare1556 Жыл бұрын
Best ❤
@ashishkumarshawhitchem2017
@ashishkumarshawhitchem2017 Жыл бұрын
we want full dp playlist
@nikoo28
@nikoo28 Жыл бұрын
yes yes yes...adding more questions soon :)
@siddharthmehta4223
@siddharthmehta4223 Жыл бұрын
good approach, but the worst explanation of the code that you have written., please explain what does every line means after the second for loop. 🤫😕
@nikoo28
@nikoo28 Жыл бұрын
what part of the code are you facing problems with? If you understand the solution perfectly writing the code for it should be trivial. We do exactly the same thing...using a for loop take one coin at a time and determine the minimum required. :)
@varshinikaithapuram6189
@varshinikaithapuram6189 Жыл бұрын
what is the use of putting Integer.MAX_VALUE here?
@nikoo28
@nikoo28 Жыл бұрын
Just a sentinal value to make writing the code easier.
@yatri6329
@yatri6329 3 ай бұрын
bekkar time waste video
@nikoo28
@nikoo28 3 ай бұрын
What problems did you face??
DP 20. Minimum Coins | DP on Subsequences | Infinite Supplies Pattern
34:15
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
Каха и лужа  #непосредственнокаха
00:15
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 94 МЛН
Coin Change - Dynamic Programming Bottom Up - Leetcode 322
19:23
Lecture 104: Minimum Number of Coins || DP Series
30:36
CodeHelp - by Babbar
Рет қаралды 152 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41