Тёмный

Unique Binary Search Trees II | Similar Problem | Recursion | Memoization | Amazon | Leetcode-95 

codestorywithMIK
Подписаться 68 тыс.
Просмотров 9 тыс.
50% 1

****************Similar Qns :
Leetcode Link - leetcode.com/p...
RU-vid Link - • All Possible Full Bina...
This is the 54th Video on our Dynamic Programming (DP) Playlist.
In this video we will try to solve a very famous DP Problem - Unique Binary Search Trees II (Leetcode-95).
We will solve it using already studied concept (similar qn video link shared above)
Trust me, this will no longer be a Medium Problem.
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Unique Binary Search Trees II
Company Tags : Amazon
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips
#interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 127   
@AbhishekGupta-if3rb
@AbhishekGupta-if3rb Год назад
Best explanation bhot video dekhi sabne bakwas explanation bataya hai...you are the best ❤.Thank you bro.Ab aaya smj m
@souravjoshi2293
@souravjoshi2293 Год назад
Sahi me yaar. Maine 2-3 videos dekhe subah se kyoki aaj late upload kara mik bhaiya ne. Kuch samajh nahi aaya. Abhi mik bhaiya ek video se ek hi Baar me sab clear, I paused the video at 7:32 and using the same concept as the similar Qn, I was able to write the entire code. Salute hai aise teaching skill ko
@wearevacationuncoverers
@wearevacationuncoverers Год назад
true man
@ugcwithaddi
@ugcwithaddi Год назад
True
@codestorywithMIK
@codestorywithMIK Год назад
It means a lot. Thank you so much ❤️❤️❤️
@AlishaKhan-ww3io
@AlishaKhan-ww3io Год назад
Now, I directly come to this channel and wait 😆
@codestorywithMIK
@codestorywithMIK Год назад
Hi everyone, Apologies for the delay in upload as you all know that I travel during weekends. 😇 Appreciate your patience . Java Code Below : class Solution { Map memo; public List allPossibleBST(int start, int end) { List res = new ArrayList(); if (start > end) { res.add(null); return res; } if (memo.containsKey(new Pair(start, end))) { return memo.get(new Pair(start, end)); } // Iterate through all values from start to end to construct left and right subtree recursively. for (int i = start; i
@ugcwithaddi
@ugcwithaddi Год назад
Dont apologise sir. You are the best. Please teach us also how to manage time like you 😥
@thevagabond85yt
@thevagabond85yt Год назад
much more viewership in lesser time than Larry's YT/@Algorithmist .power of indian market...keep uploading
@codestorywithMIK
@codestorywithMIK Год назад
It means a lot. We Indians are 💪💪💪🇮🇳🪷 Thank you so much ❤️❤️❤️🙏🙏😇😇
@EB-ot8uu
@EB-ot8uu 5 месяцев назад
India produces best teachers of the world
@ganeshmula4508
@ganeshmula4508 Год назад
very good explanation sir,as others said no one didn't given a proper explanation in youtube,thank you sir🙏🙏🙏🙏
@EB-ot8uu
@EB-ot8uu 5 месяцев назад
insane level. Loved it
@top_g755
@top_g755 Год назад
Sir iss question mei aap java ke code mei arraylist function ke andar hi define krr rhe h to recursion jb hoga to baar Barr new arraylist bn jayegi n to purani values kase milegi.... Kya hum jaise mal ko globally banaye h wase list ko nhi bna skte
@floatingpoint7629
@floatingpoint7629 Год назад
thanks for the video. agr algo ko dry kar detay tou aur bhi acha hota 😄
@codestorywithMIK
@codestorywithMIK Год назад
Apologies to have missed that. Actually i travel during weekends, that’s why couldn’t get much time. But for sure I will keep this in mind from next video ❤️❤️❤️
@floatingpoint7629
@floatingpoint7629 Год назад
@@codestorywithMIK no problem and please enjoy your weekends. it was a good practice for me. the tree got very big very soon 😂
@codestorywithMIK
@codestorywithMIK Год назад
❤️😇
@anantsingh3079
@anantsingh3079 7 месяцев назад
thank you 😊
@Piyushraj0
@Piyushraj0 Год назад
Amazing ❤
@codestorywithMIK
@codestorywithMIK Год назад
Thank you 😇
@AbhishekGupta-if3rb
@AbhishekGupta-if3rb Год назад
Description gayab hai bro
@codestorywithMIK
@codestorywithMIK Год назад
Updated 😇
@Yogesh-ei1lg
@Yogesh-ei1lg Год назад
Bhaiya aap konsi company mai ho ?
@ShubhamKumarSingh6224
@ShubhamKumarSingh6224 Год назад
bhai kam views wegaira ki wajah se rukna mat bohto achha padha rhe ho aap
@codestorywithMIK
@codestorywithMIK Год назад
Thank you shubham. It means a lot. ❤️❤️😇😇
@wearevacationuncoverers
@wearevacationuncoverers Год назад
This guys is one fire. He is simply the only guy who can make a Medium/Hard look like a cake walk. I wonder when I will be able to reach at this level
@sachinmohanty4577
@sachinmohanty4577 Год назад
🎉🎉✨✨❤️ marking attendance ... MIK can you make of beautiful arrangement 2 question as you said you will try to make it on weekend???
@codestorywithMIK
@codestorywithMIK Год назад
Hey Sachin, apologies. Actually i am travelling this weekend. Will soon try to cover that ❤️❤️❤️😇
@Prakash_8873
@Prakash_8873 Год назад
As usual best explanation. Kabhi kabhi question ka level ka credit bhi App de diya karo😂.Just kidding..... . Literally I feel Todays POTD is little bit tough question .But understand the depth of DP with binary tree concept.
@codestorywithMIK
@codestorywithMIK Год назад
😁 sure Thank you Prakash 😇❤️
@phoddaal7130
@phoddaal7130 Год назад
Sir, why it is happening that instead of map, when i used unordered_map. the code stops working. ?? it gave these errors, Line 63: Char 31: error: call to implicitly-deleted default constructor of 'Solution' vector ret = Solution().generateTrees(param_1); return ret; Line 14: Char 54: note: default constructor of 'Solution' is implicitly deleted because field 'mp' has a deleted default constructor unordered_map mp;
@codestorywithMIK
@codestorywithMIK Год назад
C++ doesn’t allow using pair inside unordered map. Hope that helps 😇❤️
@phoddaal7130
@phoddaal7130 Год назад
@@codestorywithMIK ohhh, got it, Thank u sir
@phoddaal7130
@phoddaal7130 Год назад
@@codestorywithMIK Sir can you please tell that, is Competitive Programming Necesaary to crack Big Product Based companies or, DSA and Leetcoding can get me that. Please Tell
@codestorywithMIK
@codestorywithMIK Год назад
Actually competitive programming can help in giving you a boost and confidence of not missing any OA qn. Because OA qns require deep understanding of any Data Structure . But, it’s not mandatory to crack product based companies. Me and many of my mates never did CP. But I believe that today due to excessive competition, sometimes OAs are tough and of CP level but it’s not always the case. So, it’s not mandatory but it’s a good to have if you have enough time.
@amodsings9321
@amodsings9321 Год назад
Title dena bhul gye kya bhaiya?
@codestorywithMIK
@codestorywithMIK Год назад
Just updated Thank you 😇
@Rajdweep
@Rajdweep Год назад
very hard qs bro
@codestorywithMIK
@codestorywithMIK Год назад
Indeed. For first time its tough. However if you notice the similar Qn in the Description, i had solved it before, so this qn seemed familiar
@Rajdweep
@Rajdweep Год назад
@@codestorywithMIK yaa saw that video,getting a pattern,bt have to say the pattern is very rare i have never seen this kinda qs before
@chaitanya812
@chaitanya812 Год назад
Wasn't able to solve 😢 But your video made my day
@codestorywithMIK
@codestorywithMIK Год назад
I am glad my video helped 😇❤️
@amanmathur8602
@amanmathur8602 Год назад
plaase make a solution video on leetcode 932
@codestorywithMIK
@codestorywithMIK Год назад
Sure. noted
@prashantvishwakarma6100
@prashantvishwakarma6100 Год назад
I am watching you solutions from last 10 days continuously you explain everything best way i also understand it but i am not able to do it by myself... Without looking at code what i should do ? ...Please Help
@honey6567
@honey6567 Год назад
96. Unique Binary Search Trees From Catalan series class Solution { public: int dp[20]; //catlone number prateek sir write in copy int count(int n ){ if(n==0)return 1; if(dp[n]!=-1)return dp[n]; int ans=0; for(int root=1;root
@soumyadipmajumdar4306
@soumyadipmajumdar4306 8 месяцев назад
using a pair of integers as a key in the unordered_map, and by default, unordered_map does not have a hash function defined for pairs..Need to define our own hash
@ashutoshpandey1639
@ashutoshpandey1639 Год назад
Bhaiya can you explain why we initialize result vector of TreeNode* inside our solve function , because if we make it inside it will just create a new result vector every time when solve function called , if i initialize it globally i gets error
@codestorywithMIK
@codestorywithMIK Год назад
(copied from a comment by @mosereview) - “Every recursive call returns list of roots of different BSTs possible from subtrees. So every recursive call must have different result variable. Keeping it global will keep updating the same result vector in recursive calls because global variables have only one copy.” Above is a good explanation why we keep local result for every recursive call. Hope that helps. 😇❤️
@ashutoshpandey1639
@ashutoshpandey1639 Год назад
@@codestorywithMIK Cleared bhaiya . thanks for reply❤
@tutuimam3381
@tutuimam3381 Год назад
Thanks a lot❤❤❤
@107_faizanalam2
@107_faizanalam2 Год назад
Sir,I have a question regarding memoization.. Since You have used Map to memoize it.But when we have to use map to memoize it and in which type of question we have to memoize with map instead of simple dp arrays. If you will answer i will be very grateful to you Thanks..
@ugcwithaddi
@ugcwithaddi Год назад
Every recursive call returns list of roots of different BSTs possible from subtrees. So every recursive call must have different result variable. Keeping it global will keep updating the same result vector in recursive calls because global variables have only one copy.
@codestorywithMIK
@codestorywithMIK Год назад
It totally depends on the qn. When you have to store a vector or complex result in dp then choose a map as it will be difficult to maintain that in an array. But if you have to store only a value for a given state, then choose dp array
@107_faizanalam2
@107_faizanalam2 Год назад
@@codestorywithMIK Got the point. Thanks a lot sir ☺️
@RAHULSHARMA-dl1jc
@RAHULSHARMA-dl1jc Год назад
bhaiya when i=2 means pointing at 2 ,(leftbst=1,n,2,rightbst=n) then how it supposed to store the elements for(auto lefttree:leftbst){ for(auto righttree: rightbst) { TreeNode* root=new TreeNode(i); root->left=lefttree; root->right=righttree; result.push_back(root); } } please explain this bhaiya
@adarshdhital007
@adarshdhital007 Год назад
Eat, Code,Repeat
@recessionriche
@recessionriche Год назад
Perfect explanation as always!
@codestorywithMIK
@codestorywithMIK Год назад
Thank you 😇❤️
@sourabhsinghbhadouriya9711
@sourabhsinghbhadouriya9711 Год назад
Bhai please also discuss the leetcode contest problems
@codestorywithMIK
@codestorywithMIK Год назад
I will soon start that too ❤️
@ayushkhandelwal7485
@ayushkhandelwal7485 Год назад
Bro why does it give error when I use unordered_map for memoization instead of map?
@codestorywithMIK
@codestorywithMIK Год назад
Because C++ doesn’t support pair inside unordered_map. But if you want, you will have to write your own custom hash function for your map. That’s why, it’s better to choose ordered_map
@ayushkhandelwal7485
@ayushkhandelwal7485 Год назад
Got it! Thanks sir@@codestorywithMIK
@SohelKhan-vt5ql
@SohelKhan-vt5ql Год назад
what took you so long. Been waiting for ages
@codestorywithMIK
@codestorywithMIK Год назад
Apologies for delay Sohel. Actually i usually travel during weekends. That’s why the delay. I hope my video helped 😇🙏
@Momentsofmagic28
@Momentsofmagic28 Год назад
Noone teaches like you man. I agree with the Pinned comment. You have the magic of making things simple.
@AlishaKhan-ww3io
@AlishaKhan-ww3io Год назад
You always make things look so easy. You are the best tutor mik bhaiya
@amarnathprajapati2543
@amarnathprajapati2543 Год назад
Best Explanation Sir This video is very helpful.🙏🙏
@codestorywithMIK
@codestorywithMIK Год назад
Thank you 😇😇
@top_g755
@top_g755 Год назад
Thankyou so much sir❤ may allah give u everything u want
@codestorywithMIK
@codestorywithMIK Год назад
Means a lot 😇❤️
@top_g755
@top_g755 Год назад
@@codestorywithMIK Sir iss question mei aap java ke code mei arraylist function ke andar hi define krr rhe h to recursion jb hoga to baar Barr new arraylist bn jayegi n to purani values kase milegi.... Kya hum jaise mal ko globally banaye h wase list ko nhi bna skte
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Год назад
Good explanation please make video on tabulation approach
@codestorywithMIK
@codestorywithMIK Год назад
Sure thing. Will cover in DP concepts soon.
@chaitanya812
@chaitanya812 Год назад
what would be the time complexity after memoise ?
@kishan.17
@kishan.17 Год назад
Thanks soo much bro.pls make a video on Pointers bro pls ❤
@codestorywithMIK
@codestorywithMIK Год назад
Thank you so much 😇🙏 Can you elaborate what exactly on pointers you want the video ?
@wakeuppeggy
@wakeuppeggy Год назад
#augustchallengewithmik Love you bhaiya
@codestorywithMIK
@codestorywithMIK Год назад
Let’s keep it going 🔥🔥💪 My full support, love and respect to you guys 😇
@sumitbaghel6203
@sumitbaghel6203 Год назад
Phele wali video dekhi thi pr acche se samaj nahi aaya tha pr iss video m samaj aa gaya. Thank you ❤
@codestorywithMIK
@codestorywithMIK Год назад
I am so glad it helped 😇🙏
@rishabhprasad8638
@rishabhprasad8638 Год назад
what's wrong with this code?? class Solution { List result ; public List generateTrees(int n) { result = new ArrayList(); return solve(1, n); } public List solve(int start, int end){ if(start > end){ result.add(null); return result; } if(start == end){ result.add(new TreeNode(start)); return result; } for(int i=start;i
@Momentsofmagic28
@Momentsofmagic28 Год назад
Every recursive call will bring new list of roots of subtree BST. You have used a global result and you are updating same result for every recursive call. Slight modification of your code fixed the issue - class Solution { public List generateTrees(int n) { return solve(1, n); } public List solve(int start, int end){ List result = new ArrayList(); if(start > end){ result.add(null); return result; } if(start == end){ result.add(new TreeNode(start)); return result; } for(int i=start;i
@poojabennabhaktula4883
@poojabennabhaktula4883 3 месяца назад
Kudos to your explanation!!!
@sauravchandra10
@sauravchandra10 Год назад
Mujhe laga aaj video nahi ayegi, toh atleast 3 4 videos dekh ke samaj aaya ache se
@codestorywithMIK
@codestorywithMIK Год назад
I hope my video helped. Apologies for delay, as I usually travel during weekends 😇🙏
@sauravchandra10
@sauravchandra10 Год назад
@@codestorywithMIK Aapki videos se kisko nhi samaj ayga 😁
@codestorywithMIK
@codestorywithMIK Год назад
😇😇🙏🙏
@humanity7880
@humanity7880 Год назад
Amazing explanation sir!!! Much much appreciated please don't stop making these videos one day this channel will hit 1 million soon❤
@codestorywithMIK
@codestorywithMIK Год назад
Means a lot 😇❤️🙏 Hope so it reaches more people ❤️❤️
@jawwadumar2100
@jawwadumar2100 Год назад
isn't nth Catalan no : (2n)! / ((n + 1)! * n!)
@codestorywithMIK
@codestorywithMIK Год назад
Actually there is an alternative expression for nth catalan number , which you can see here at the wikipedia - en.m.wikipedia.org/wiki/Catalan_number
@jawwadumar2100
@jawwadumar2100 Год назад
@@codestorywithMIK yeah okay .. thanks man
@herculean6748
@herculean6748 Год назад
very well explained!!
@codestorywithMIK
@codestorywithMIK Год назад
Thank you 😇
@anuppatankar4294
@anuppatankar4294 Год назад
Great Video 👌🏻
@MayankSinghNegi24
@MayankSinghNegi24 Год назад
Leetcode 2808 please
@DURGAMABHILASH
@DURGAMABHILASH Год назад
please share notes also
@aman3210
@aman3210 Год назад
Thanks+4;
@codestorywithMIK
@codestorywithMIK Год назад
😇❤️
@Saryupareen
@Saryupareen Год назад
can we use unordered map here?
@codestorywithMIK
@codestorywithMIK Год назад
Actually, C++ doesn’t allow using pair inside unordered map. So it won’t work. Hope that helps 😇❤️
@Saryupareen
@Saryupareen Год назад
@@codestorywithMIK got it
@simardeepsinghmudhar7065
@simardeepsinghmudhar7065 Год назад
Great Explanation and thanx for telling about the catalan number as well.
@codestorywithMIK
@codestorywithMIK Год назад
Glad it was helpful! 😇🙏
@ss8273
@ss8273 Год назад
bhaiya op++
@codestorywithMIK
@codestorywithMIK Год назад
❤️🙏
@prashantgupta9502
@prashantgupta9502 Год назад
Please make videos on SQL also only you teach the best way
@codestorywithMIK
@codestorywithMIK Год назад
Thank you Prashant. It’s first time someone has asked me for SQL. I will definitely plan SQL playlist too ❤️😇🙏
@souravjoshi2293
@souravjoshi2293 Год назад
Sabke videos dekha tha aur fir aapke dekhta tha just to compare. Now I only watch your videos. Simplest explanation Hota hai hamesha. Thanks as always
@shivamvishawakarma-z6o
@shivamvishawakarma-z6o Год назад
bhut pyara khela bhai tumne ...
@146_shashanks4
@146_shashanks4 Год назад
your explanation is very neat and clean bro.
@codestorywithMIK
@codestorywithMIK Год назад
Thank you so much 😇🙏
@sauravbiswajit8091
@sauravbiswajit8091 Год назад
Thanks a lot
@codestorywithMIK
@codestorywithMIK Год назад
❤️❤️
@sauravbiswajit8091
@sauravbiswajit8091 Год назад
Is it okay to not able to crack this problem although I have solved full binary tree walA PROBLEM , like I feel ki mere se nahin hoga
@codestorywithMIK
@codestorywithMIK Год назад
Yes Saurav, that’s totally fine. Don’t worry. But make sure you understand that the code structure of both problems were similar. So basically this is a pattern and there are similar other qns out there falling under such pattern. I know it’s not possible to remember all pattern. So the best way is to treat every problem as new and start solving it from scratch.
@sauravbiswajit8091
@sauravbiswajit8091 Год назад
@@codestorywithMIK yeah sure thanks sirrr
@utkarshsrivastava5003
@utkarshsrivastava5003 Год назад
bhai subah se wait kar rahe the yaar
@codestorywithMIK
@codestorywithMIK Год назад
Apologies for delay. Actually i usually travel during weekends. That’s why the delay. I hope my video helped 😇🙏
@codeandtalk6
@codeandtalk6 Год назад
Solved it on own ❤❤
@codestorywithMIK
@codestorywithMIK Год назад
I am the happiest when i hear this 😇🙏
Далее
"Когти льва" Анатолий МАЛЕЦ
53:01
Unique Binary Search Trees 1 || #DynamicProgramming
22:56
Leetcode 95 Unique Binary Search Trees II
10:34
Просмотров 3,1 тыс.
Unique Binary Search Trees II - Leetcode 95 - Python
12:51