50 Maximum Path sum | From leaf node to leaf node

  Рет қаралды 100,494

Aditya Verma

Aditya Verma

Күн бұрын

Пікірлер: 597
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
WORKING CODE FOR: leetcode.com/problems/binary-tree-maximum-path-sum/ int solve(TreeNode* root,int& res) { if(root==nullptr) { return 0; } int l=solve(root->left,res); int r=solve(root->right,res); int temp=max(max(l,r)+root->val,root->val); int ans=max(temp,l+r+root->val); res=max(res,ans); return temp; } class Solution { public: int maxPathSum(TreeNode* root) { int res=INT_MIN; solve(root,res); return res; } };
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Just a minor change from what I taught, think about it and you will get for sure. kzbin.info/www/bejne/d6OxqqimmpKLfpI
@cs208anjaysahoo2
@cs208anjaysahoo2 4 жыл бұрын
Bhaiya above solution is for the previous problem (Video number 49) and it works perfectly fine, but for this question, your solution in the video doesn't work. Just now completed your DP series and it is the best series on DP .Thanks a lot for making these video from now on my fear for DP has reduced. Looking forward to watching your other video too:)
@sohelsheikh1934
@sohelsheikh1934 3 жыл бұрын
Video solution will not work for Negative values , Correct Solution : - eg case = -10 -1 0 3 class Tree { int res ; int maxPathSum(Node root) { res = Integer.MIN_VALUE; solve(root); return res; } int solve(Node root){ if(root ==null){ return 0; } if (root.left == null && root.right == null) return root.data; else{ int l = solve(root.left); int r = solve(root.right); if( root.left == null){ return r + root.data; } if( root.right == null){ return l + root.data; } int temp = Math.max(l,r) + root.data; res = Math.max(res, l+r+root.data ); return temp; } } } Your Welcome :)
@hemanthlishetti7536
@hemanthlishetti7536 3 жыл бұрын
this code is also not working for test case -9 6 -10
@raajanashishpal4984
@raajanashishpal4984 3 жыл бұрын
This will work for all the cases public class MaximumPathSumLeafToLeaf { private static int maxPathSum = Integer.MIN_VALUE; public static void main(String[] args) { // int[] treeArray = new int[] {20, 2, 1, 3, 30, 32, 28, 33, 26, 34, 35, 36, 24, 23}; int[] treeArray = new int[] {10, 5, -3, 12}; Node root = BinaryTree.initialiseTree(treeArray); maxPathSum(root); System.out.println(maxPathSum); } public static int maxPathSum(Node root) { // Base condition if (root == null) { return 0; } if (root.left == null && root.right == null) { return root.data; } // Hypothesis step int lpsum = maxPathSum(root.left); int rpsum = maxPathSum(root.right); if (root.left == null) { return rpsum + root.data; } if (root.right == null) { return lpsum + root.data; } // Induction step // When current node is root node for path giving maximum path sum int pathSumToPass; pathSumToPass = Math.max(lpsum, rpsum) + root.data; // data+lda+rda when current node is root node for path giving maximum path sum // Choose the case for maximum path sum int tempPathSum = Math.max(pathSumToPass, root.data + lpsum + rpsum); maxPathSum = Math.max(maxPathSum, tempPathSum); return pathSumToPass; }
@0anant0
@0anant0 4 жыл бұрын
49 of 50 (98%) done! Finally finished the series! It was a great experience! Thanks!
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Congratulations Bro, I was waiting for this, saw your comment on each video 😅
@0anant0
@0anant0 4 жыл бұрын
@@TheAdityaVerma Thanks! I had code for almost all the problems but did not understand the underlying patterns -- it was evident from the copious amount of comments I had added to each code to try to understand. :-) Now, when I visit the code, it makes a lot of sense. e.g. today, I was looking at LC 664 'strange printer' and LC 241 'diff ways to form expr' code and realized it was the MCM pattern! It would be great if you could add the remaining DP patterns. BTW, I also completed recursion and binary search series. I am going to watch each and every video of yours!
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
if it helps , i think that video 27 was this problem - longest palindromic substring , so now you can go ahead and get 100% completion :)
@kushal7406
@kushal7406 3 жыл бұрын
Yeah, same dude. Thanks to aditya bhaiya for such a great content🤗
@WhyYouN00B
@WhyYouN00B 2 жыл бұрын
Bhai aapki placement kaha hui hai aditya sir videos dekh kar
@shahabakhtarrabbani6864
@shahabakhtarrabbani6864 3 жыл бұрын
Legends say he's still having his lunch :D Thanks a lot for this playlist!!
@dhruvagarwal646
@dhruvagarwal646 3 жыл бұрын
At the last just want to say: "THOSE WHO CAN'T REMEMBER THE PAST ARE CONDEMNED TO REPEAT IT" ~Dynamic Programming
@opera3846
@opera3846 3 жыл бұрын
💯
@ogbuddha7835
@ogbuddha7835 2 жыл бұрын
Now i can understand why
@thiswasme5452
@thiswasme5452 2 жыл бұрын
Great !!
@ManojKumar-rg8ez
@ManojKumar-rg8ez 2 жыл бұрын
If you watch any of the video of this channel, you are bound to watch all the videos. It's safe to say these videos gives wings to everyone who wants to fly in the sky of the algorithm's space on it's own. I have never came across the videos which explain such a wonderful manner, now recursion does seems like a magic which we can perform!
@vishaljaiswal1604
@vishaljaiswal1604 3 жыл бұрын
Phewww...Finished all the 50 Questions and What a journey it has been, right from scratch to solving trees,I never did this in college but after 5 years of work ex, I landed up here and learned dynamic programming.Thank You, Aditya Verma, even a gazillion of thank you will not be enough, and Above all the way you explained each and everything was mind-boggling and magical. More power to you.Keep spreading knowledge.Forever Grateful
@vishal_rex
@vishal_rex 3 жыл бұрын
Finally I've completed your entire DP playlist. Before that, I have completed recursion playlist also. Here are some changes in my problem solving ability: * I'm not afraid of DP anymore. * Solved C type ques of live contest in Codeforces using DP. * Solved daily leetcode challenge ques which was based on 3d matrix DP on knapsack. * Partially solved Codechef's long challenge's last ques (toughest) using recursion. I followed one approach while watching your every video. I made sure to code along with your explanation. I paused video after getting to know the problem statement, most of the time I could derive the solution myself from the previous analysis of yours. I went through entire comment section of each video in order to get more info about the solution. Thankyou so much for such a quality content ❤❤❤
@thinkingmad1685
@thinkingmad1685 3 жыл бұрын
Wow nice to hear that ,I m going to start this journey now wish me luck
@vishal_rex
@vishal_rex 3 жыл бұрын
@@thinkingmad1685 all the best
@The_Promised_Neverland...
@The_Promised_Neverland... 3 жыл бұрын
Baasss bhai kitna fekega😂
@deepakgurjar3746
@deepakgurjar3746 2 жыл бұрын
chal bhai is que ka soln to bta de...]
@vishal_rex
@vishal_rex 2 жыл бұрын
Revisiting this comment thread after 1 year.. updates: I'm SDE at Amazon that too being from tier3
@robbie26101990
@robbie26101990 8 ай бұрын
1.4 mill started this journey , kudos to the 92k who finished it 😄
@lifehustlers164
@lifehustlers164 Жыл бұрын
Completed all videos of this series. What a journey of around 30-35 days.(from july 1 2023 to august 3 2023), Now i am pretty much confident in DP.Thanks @adityaverma for this amazing series.
@SajidShaikh-ie1ww
@SajidShaikh-ie1ww 2 жыл бұрын
Finally completed this awesome playlist...thank you so much @Aditya...we need more people like you...pehle DP ke naam se darta tha...ab lagra hai yahi tha DP... blessed to have you as our teacher ❤️❤️❤️
@monilcharola6873
@monilcharola6873 2 жыл бұрын
One minor correction according to me :- What will happen if the current node has only one child and it returns the -ve value. The other child is null so it would return 0. And taking maximum of them will result into 0. Thus max(l,r)+curr->val will be equal to ccurr->val (considering the value returned from the existing child is more negative). Thus in the end we would return the curr->val which means we broke the path from leaf to leaf. Consider this part for the node with value 10 and having right child value -25 and left child value 0. For that node max(l,r)+curr->val will be equal to curr->val , which will be returned. Thus breaking the path to leaf node. What we can do is to check before returning. ----------------Method 1--------------------------------------- if(curr->left == NULL) return (r+curr->val); else if(curr->right == NULL) return (l+curr->val); else return (max(l,r) + curr->val); If you don't want to do this work just change the base condition ----------------------Method 2------------------------- if(root==NULL) return INT_MIN -------------------------------------------------------------- I deserve to be wrong. Any suggestions or criticisms are welcomed.
@utkarshjain9221
@utkarshjain9221 2 жыл бұрын
Really Appreciated this bugged me right from the start of the video
@aakanshakowerjani9614
@aakanshakowerjani9614 Жыл бұрын
In Method 2, what if the root is a leaf node. In that case both of its child will be null and as per method 2 we will get INT_MIN from both, now when we do max(INT_MIN,INT_MIN)+root.val => this will give unexpected value eventhough it should give root.val only.
@Anand-wi4yb
@Anand-wi4yb 4 жыл бұрын
Finally completed this amazing playlist. I am feeling lucky that I found your videos; otherwise, I would never have learnt DP! Thank you very much for giving us such a wonderful course for free.
@lifewithniharikaa
@lifewithniharikaa 3 жыл бұрын
Just completed the playlist . It changed my whole perception about coding. THANK YOU @Aditya Verma
@nikeshshetty3694
@nikeshshetty3694 5 ай бұрын
As everyone else in the comment section has already said, this is the best DP course without a doubt. Thanks a lot for this!
@ishan5456
@ishan5456 4 жыл бұрын
Hands down !! Best series for DP ..... Thnks for all the effort besides your job ..... Please complete the playlist by adding LIS and DP on grids section.... Keep going !!
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Noted
@ishan5456
@ishan5456 4 жыл бұрын
@@TheAdityaVerma just a suggestion though....... I think if you want to move ahead with different playlists , you could just make intro videos for remaining topics like DP on grids, kadane , lis and Fibonacci advanced.... in which you could just tell about the list of problems that you told about in introduction to dp video ..... This way you could also move ahead with different playlists and this playlist would also be somewhat completed.... !!!
@anonymous-kl1un
@anonymous-kl1un 4 жыл бұрын
@@TheAdityaVerma bhaiii mein kabse wait karr rha tha ki DP ki playlist update hooooo....parr yaar update toh hui magar koi video nahi aaya? Shayad netConnection chala gaya hoga aapka. Ek baar check karlo ki koi video nahi upload hui nayi bhaiijaaaan. Please daaldo DP prr aur videosssss.....meri bohot bhaari request hai aapse ye. Please mere bhagwaan pleasee
@sidhantchandak5152
@sidhantchandak5152 4 жыл бұрын
@@TheAdityaVerma Yes, Please keep making more videos. I am a huge fan. I binge-watched all your videos within a week. Your notes are superb!
@ViralAgrawal12321
@ViralAgrawal12321 4 жыл бұрын
@@TheAdityaVerma Sir, thank you very much for such a great explanation. Please provide at least the problem statement's link of remaining questions which you discussed initially like.. Fibonacci(7) Lis(10) Kadane's Algorithm (6)
@thesaloniguptaa
@thesaloniguptaa 3 жыл бұрын
Finally Completed, learned a lot from this series, can't wait to watch more such content. Keep posting :)
@rahulnagwanshi2348
@rahulnagwanshi2348 3 жыл бұрын
I completed this series in 3 days, feeling much more confident in DP now, learned so much in these 3 days, my confidence went from 0 to 100 real quick I can say lol. If possible please update this series with the leftover problems you mentioned in the first video and also it will be much helpful if u make a dedicated series on Graph. *Thank you ADITYA (The man who made DP easy )*
@ogbuddha7835
@ogbuddha7835 2 жыл бұрын
In 3 days? Seriously?
@rahulnagwanshi2348
@rahulnagwanshi2348 2 жыл бұрын
@@ogbuddha7835 yes bro I was learning in God mode back then
@naive-fleek7420
@naive-fleek7420 2 жыл бұрын
@@rahulnagwanshi2348 from where did u learned graphs and trees?
@rahulnagwanshi2348
@rahulnagwanshi2348 2 жыл бұрын
@@naive-fleek7420 bro unfortunately i couldn't find a dedicated series of graph and trees, i learned it from gfg blogs and take u forward yt channel and few others I don't remember
@soumyachaudhary2468
@soumyachaudhary2468 2 жыл бұрын
@@naive-fleek7420 codencode channel se pdh le bro graph and for trees mycodeschool channnel ki data structure
@patelchintu6492
@patelchintu6492 3 жыл бұрын
Finally completed the whole DP series...Very well learned...Thanks to this great man!!!
@mayankpatel6735
@mayankpatel6735 3 жыл бұрын
Finally Completed the series in five days! I have practiced some problems and found them very easy. Thanks a lot for this free material.
@priyajaiwal8072
@priyajaiwal8072 2 ай бұрын
Completed entire Dp series. midway through other series. Thank you would not be enough but here i am, Thank you for this gem of a playlist. I am also from 2020 batch like you but the way you explained everything reminded me of that topper friend who explains everything in short and crisp way just 5 minutes before the exam, only here you explained everything in details. I started Dp with thinking it as the most difficult topic ever but tbh if you do enough coding you'll release Array is the one hiding all the weirdness and Dp is actually very chill. Imma update this thread soon. I've read comments, so here to the one who will come in future. "Hey, stick to it, this works wonder!".
@rishikumarjha5281
@rishikumarjha5281 2 жыл бұрын
100% done from 1 - 49 >>finishhed the entire series....received tons of knowledge
@alpishjain1317
@alpishjain1317 3 жыл бұрын
completed the whole playlist in 4 days all of the videos were amazing.The hard part is to keep the concepts in mind,hopefully i'll remember everything.😅
@akshit109
@akshit109 4 ай бұрын
me in 5 days... 10 videos/day
@shreeramgoyal84
@shreeramgoyal84 3 жыл бұрын
Hands down the best series. Never understood why would we return temp before watching this series especially do on trees. Thank you so much!!!
@184alokkumar2
@184alokkumar2 2 жыл бұрын
50/50 done. Finally finished the series!🔥🔥
@mansisaxena815
@mansisaxena815 4 жыл бұрын
Finally, I have completed this DP playlist. One of the best tutorial I have ever seen. My concepts of DP are cleared now. 👍👍
@mananmakwana4324
@mananmakwana4324 3 жыл бұрын
One of the best series on DP, i had ever found. Thanks!! 💓
@vineetjadhav1785
@vineetjadhav1785 Ай бұрын
Finally i completed this playlist, kudos to those who completed this masterpiece , I was scared of DP but now I can identify and tackle problems on my own and can write up to 90% of the code by myself. Its really helped me to cop-up from my fear of DP. Thanks Aditya Bhai you are a Great Teacher ❤❤
@keshavraghav3896
@keshavraghav3896 2 жыл бұрын
First time I completed the whole playlist on KZbin. now i am going to solve all dp problems on leetcode. Thanks Aditya Verma, you made me realize that Dp, is really interesting.
@valorantrizz
@valorantrizz 2 жыл бұрын
Thank you Aditya bhaiya. You will be remembered till centuries
@preethamnaik7442
@preethamnaik7442 5 ай бұрын
Finished the series, used to think DP as some magical thing that is very tough and complex, but you explained it in the easiest way possible. Thanks Man!🙌🙌
@nikeshshetty3694
@nikeshshetty3694 5 ай бұрын
Yes sari pathera
@aoi_sora5667
@aoi_sora5667 4 жыл бұрын
Finally Completed this awesome playlist. Lockdown time used successfully. Thank you very much for this playlist. It is like a gift from God.
@adeshpradhan1314
@adeshpradhan1314 4 жыл бұрын
I have gone through so many channels, but your teaching is best, gone through all videos , thanks a lot for this series and efforts
@chaitanyakumar9229
@chaitanyakumar9229 3 жыл бұрын
i completed 50 videos within a few days it was soo interesting and this is the best series on dp, waiting for more videos :)
@nikhilrajsoni7390
@nikhilrajsoni7390 2 жыл бұрын
finnaly this series is completed,but i dont want to complete this one coz this series was too much fun,i just wanted this series to be super duper long lasting,it was the greatest series ever,thank you bhaiyaa!!!
@idealspeaker1377
@idealspeaker1377 Жыл бұрын
Absolutely breathtaking.... GOAT teacher.... hands down sir!
@ayushkoul5065
@ayushkoul5065 2 жыл бұрын
//Maximum Path Sum between any 2 Leaf Nodes /* Points to Note / Corrections : 0. A potential answer is only that path which starts & ends at leaf node...temp can never be a potential answer 1. For leaf nodes we cannot calculate 'ans' or update 'res' because to calculate ans..the current node must have left & right subtree..so that both ends of the path lies on the left and right of cur node. (tbi woh node karta-dharta banega aur potential ans bnega) 2. For node having only 1 child(left or right) we cannot calculate 'ans' (similar to 1) because path's both end must lie one on left & other on right side of current node. (karta-dharta) 3. So for above 2 cases we directly return temp...and we are not calculating 'ans' or updating the 'res'. 4. Here we are asked path between leaf nodes...that means path must start & end at leaf node, so temp will be equal to root->data+max(l,r)...and we cannot ignore both the left (l) or right(r) if they are negative as we did in previous question because then the path will no more be starting from a leaf node. 5. ans=max(temp,root->data+l+r) is wrong...Same reason as temp can never be a potential ans...as it is not ending at a leaf node.. */ //Code:- class Solution { public: int findMaxPathSum(Node *root,int &res) { if (root==NULL) return 0; int lsum = findMaxPathSum(root->left,res); int rsum = findMaxPathSum(root->right,res); if (!root->left and !root->right) //See point 1 & 3 return root->data; if (!root->left) //See point 2 & 3 return root->data + rsum; if (!root->right) return root->data + lsum; int temp=root->data+max(lsum,rsum); //See point 4 int ans=root->data+lsum+rsum; // See point 5 res = max(res,ans); return temp; } int maxPathSum(Node *root) { int res=INT_MIN; int ans = findMaxPathSum(root,res); if(!root->left or !root->right) res=max(res,ans); return res; } };
@Tushar-qd8ow
@Tushar-qd8ow 2 жыл бұрын
Very well explained
@varshasingh6627
@varshasingh6627 2 жыл бұрын
I am not getting your second point if there is on child why we cannot calculate the ans?
@sayantaniguha8519
@sayantaniguha8519 2 жыл бұрын
int solve(Node* root, int &maxi) { if(!root) return 0; int leftSum = solve(root->left, maxi); int rightSum = solve(root->right, maxi); // Negative subtree sum cannot be avoided[except for avoiding leaf-node's subtree(s) - which doesn't exist] // For-non leaf node, we've to consider either subtrees & leaf-node wont have any sub-tree(s) int temp = root->data + max(leftSum, rightSum); //if that node isn't answer int rel = root->data + leftSum + rightSum; //if that node is answer int ans = rel; maxi = max(maxi, ans); return temp; } int maxPathSum(Node* root) { // Your code goes here int maxi = INT_MIN; solve(root,maxi); return maxi; } What is the mistake here?
@tk8782
@tk8782 2 жыл бұрын
Thank You !! big brother . My fear of DP has almost gone now. Credit goes to you only 👏👏.
@dp-ev5me
@dp-ev5me 3 жыл бұрын
Have watched all of the dp videos(Binge watched in exam break), found them all incredibly helpful. Thank you sir.
@shubhamjain5132
@shubhamjain5132 3 жыл бұрын
just completed the entire series on DP and it was just awesome. Thank you bro for making my life easy on DP. :) Best source to learn DP
@hemantdhankar121
@hemantdhankar121 3 жыл бұрын
Hi Aditya, I just finished this series and wanted to thank you for putting in so much effort. You have done amazing work. From the first video to the last video, the passion and enthusiasm in your voice kept me motivated. GREAT SERIES! thank you again.
@AnshKumar-dp1st
@AnshKumar-dp1st 2 жыл бұрын
Finally completed the series, it will be great if all the topics mentioned in first video were covered, but Still it was a great playlist ♥️.
@vishalsnsingh
@vishalsnsingh Жыл бұрын
complete whole playlist today😊 you're good of DP
@adityaagarwal5348
@adityaagarwal5348 Жыл бұрын
Finally completed this series and I never thought DP was not about 2d array but it is about recursion and how you can find patterns. Always thought of DP as most difficult problem but after recursion + DP series, it looks so much fun.
@MovieLover997
@MovieLover997 Жыл бұрын
I can't have word to express my feelings on your explanation on this DP series, it's just awesome. I tried to learn DP from many courses and KZbin channels but still no one can explain like you. Thank you for your great effort bhaiya.
@raavimann4472
@raavimann4472 4 жыл бұрын
Sir can you please make videos on graphs also. Because after dp the next most difficult topic is graphs which is asked in many interviews. And please sir complete this playlist.This is the best explanation ever of dp.
@Gourav-kl5jt
@Gourav-kl5jt 2 жыл бұрын
Finally completed the DP playlist. It was really a great experience and now cleared all the concepts of this playlist.
@rakeshkumaryadav1117
@rakeshkumaryadav1117 2 жыл бұрын
Finally when see this lecture Tree topic cleared no one explain better than this thanks for providing such wonderful series
@heenaagarwal6795
@heenaagarwal6795 4 жыл бұрын
Hey Aditya, really hoping that you will continue teaching all these complex concepts in such a simple and easy to understand language. Please keep uploading new videos on new topics. Thanks :)
@rajshreegupta4454
@rajshreegupta4454 4 жыл бұрын
Finally completed all 50 videos. Thanks for lot for this amazing playlist. Have really started enjoying DP than scaring it!!
@vii2sharma
@vii2sharma 2 жыл бұрын
Thank your Aditya sir...I loved your DP series...
@dharani8871
@dharani8871 Жыл бұрын
Thank you 🥺.....i have even improved my problem solving skills.....
@rockington
@rockington Жыл бұрын
Finally completed this legendary playlist on Dynamic Programming. Thank you Aditya bhaiya😊😊 DATE- 27/2/2023, TIME- 2.20 AM
@mainaksanyal9515
@mainaksanyal9515 4 жыл бұрын
Aaj se do week phele dynamic ka dhang ka video dhund raha tha tab ye playlist recommend kiya youtube ne. Jab dekhne baitha tha ek dar the dynamic ke liye. Ab ye hai ki koi bhi problem aa jaye toh darunga toh bilkul nhi. Thanks a lot Aditya. Aur waiting for playlist on Greedy ^_^
@pralaydas6400
@pralaydas6400 4 жыл бұрын
Sir, your quality of techniques is really awesome, I never see any one who teaches the programming like this, sir one request please kindly upload the other parents problem such as longest increasing subsequence, fibonacci, kadane's , dp on grid and others , it will be very helpful for me and other students also.
@darkknightgaming3375
@darkknightgaming3375 2 жыл бұрын
Man, your way of teaching is just awesome!! best playlist for DP ever!!
@himanshutekchandani2363
@himanshutekchandani2363 2 жыл бұрын
go watch take you forward playlist then you won't find this that much amazing
@sonal9kothari
@sonal9kothari 4 жыл бұрын
Thanks @Aditya. I watched this playlist(MCM skipped) in just 2 days, and now I am able to solve many of the medium level DP question from leetcode easily.
@the-sporting-record-book
@the-sporting-record-book 2 жыл бұрын
Done with the playlist Thanks for making me friends with DP problems 👏
@Hereitus
@Hereitus 4 ай бұрын
finally completed your DP playlist ... you are a legend ....thanks... 😀😀
@AmimulEhsaan
@AmimulEhsaan 2 жыл бұрын
Finally, end of the playlist. Thanks to the LEGEND
@soumikroy4600
@soumikroy4600 4 жыл бұрын
Humble request to you brother.. Please complete DP playlist.
@priyanshusinghal373
@priyanshusinghal373 Жыл бұрын
I took my time....but still finished this series now will see.... implementing these in my cp process,revising and practicing more and more questions..... Thanks bhaiya
@akshaychordia8724
@akshaychordia8724 3 жыл бұрын
finally, I have completed this DP playlist. One of the best tutorial I have ever seen. My concepts of DP are cleared now. 👍
@danishakhtar2683
@danishakhtar2683 3 жыл бұрын
finally i completed it now for me DP is like a cakewalk a very big thanks ADITYA you had done such spectacles work for all the coders
@siddhantjain1546
@siddhantjain1546 Ай бұрын
Feels good to finally complete this playlist! Great content!
@AmanRaj-MNNIT
@AmanRaj-MNNIT 2 жыл бұрын
Thank You for the such great content ,learned a lot and the best part u categorized all the types of questions .
@sahilpatil2240
@sahilpatil2240 2 жыл бұрын
Best DP resource of all time🔥 Thank you sir!
@anchalanju2422
@anchalanju2422 2 жыл бұрын
Best DP series, now I feel much confident in dp. Thank you for teaching in such a great way.
@sarvottamkaushik3720
@sarvottamkaushik3720 4 ай бұрын
Today reached this last video.... thank you for amazing playlist.
@sandeepm2723
@sandeepm2723 4 жыл бұрын
For all those folks who got wrong answer on GFG or leetcode here is the correct code just add these base condition and you are good to go aditiya bhaiyaa missed these edge case apart from that solution work perfectly fine: int solve(Node* root,int &answer) { if(root == NULL) { return 0; } if(root -> left == NULL && root -> right == NULL) { return root -> data; } if(root -> left == NULL) { return (solve(root -> right,answer) + root -> data); } if(root -> right == NULL) { return (solve(root -> left,answer) + root -> data); } int ltsum = solve(root -> left,answer); int rtsum = solve(root -> right,answer); int temp = max(ltsum,rtsum) + root -> data; int solution = ltsum + rtsum + root -> data; answer = max(answer,solution); return temp; }
@UECDishaKhattri
@UECDishaKhattri 4 жыл бұрын
Thanks a lot for working code
@tonyriddle7646
@tonyriddle7646 4 жыл бұрын
not working for me.. //here is my code int helperLeafToLeafMaxm(Node* root, int &res){ if(root == nullptr) return 0; if(root->left == nullptr && root->right == nullptr){ return root->data; } if(root->left == nullptr){ return (helperLeafToLeafMaxm(root->right, res) + root->data); } if(root->right == nullptr){ return (helperLeafToLeafMaxm(root->left, res) + root->data); } int lsolve = helperLeafToLeafMaxm(root->left, res); int rsolve = helperLeafToLeafMaxm(root->right, res); int temp = max(lsolve, rsolve) + root->data; int ans = lsolve+rsolve+root->data; res = max(res, ans); return temp; } int maxPathSum(Node* root) { // code here if(root == nullptr) return 0; int res = INT_MIN; return helperLeafToLeafMaxm(root, res); }
@hemanthlishetti7536
@hemanthlishetti7536 3 жыл бұрын
@@tonyriddle7646 return helperLeafToLeafMaxm(root, res); This is wrong..i.e u are returning temp...instead of returning res; ur modified maxPathSum should be int maxPathSum(Node* root) { // code here if(root == nullptr) return 0; int res = INT_MIN; helperLeafToLeafMaxm(root, res); return res; }
@hemanthlishetti7536
@hemanthlishetti7536 3 жыл бұрын
Heyy sandeep, can u help me understand why u have included the below extra 2 cases. My argument : is calculating l and r in the next step will take care of these extra 2 cases. But if iam do like that iam getting wrong answer..Iam not getting the exact idea of aditya verma's mistake. if(root -> left == NULL) { return (solve(root -> right,answer) + root -> data); } if(root -> right == NULL) { return (solve(root -> left,answer) + root -> data); }
@suryapratap8680
@suryapratap8680 2 жыл бұрын
@@hemanthlishetti7536 same doubt and also, why is there a need to check for leaf node, as for a leaf node we will get ltsum and rtsum to be 0, hence tmp will be equal to value at node. which is what he was explaining in @10:35, then stopped mid way.
@Coolharshit149
@Coolharshit149 3 жыл бұрын
Hands down to the best DP series ever. Thanku so much Aditya Verma
@ishaankulkarni49
@ishaankulkarni49 3 жыл бұрын
reached the end of this brilliant playlist. cat thank you enough for making it!
@priyakoshta7129
@priyakoshta7129 3 жыл бұрын
Finally completed this. Thanks a lot Aditya for this amazing series. I did not get bored and was never lazy to drop this series in between. The way you teach is really interactive and it is not like one way delivery of lectures it is infact a two way interaction.
@Sachinsachin-th4gm
@Sachinsachin-th4gm Жыл бұрын
Just completed the series...thanks for ur help❤
@srijansingh7070
@srijansingh7070 3 жыл бұрын
THANKS FOR THIS COURSE ADITYA >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HELPED ALOT >......................
@jayshree7574
@jayshree7574 4 жыл бұрын
finally it's over, this playlist will always have a special place in my heart as it taught me a topic like dp, which was seriously scary!!!! Wll miss, "Hi again", anyways going to do a lot questions now!!! So that I can start the heap series. This is one of the best resources, recommending everyone.
@ViralAgrawal12321
@ViralAgrawal12321 4 жыл бұрын
Sir, thank you very much for such a great explanation. Please provide at least the problem statement's link of remaining questions which you discussed initially like.. Fibonacci(7) Lis(10) Kadane's Algorithm (6)
@ViralAgrawal12321
@ViralAgrawal12321 4 жыл бұрын
please make this comment reach till aditya verma please it will help us
@tonyriddle7646
@tonyriddle7646 4 жыл бұрын
@@ViralAgrawal12321 nhi degi
@ViralAgrawal12321
@ViralAgrawal12321 4 жыл бұрын
@@tonyriddle7646 ok..bhai
@manikrangar6357
@manikrangar6357 3 жыл бұрын
Best ever dp playlist on youtube . Too good bro
@puneethv4138
@puneethv4138 3 жыл бұрын
COMPLETED :-)....🔥💥👌.... Waiting for Re-entry of the leader..
@himanshugupta7010
@himanshugupta7010 3 жыл бұрын
finally completed this series . thanks a lot man for this series . now from today I can start solving problems of dp and now I am confident ki m kar lunga
@vasutiwari4187
@vasutiwari4187 3 жыл бұрын
no one : aditya bhaiya posting 50 videos in one day
@rishisharma0930
@rishisharma0930 Жыл бұрын
completed all the 50 videos It is a beautiful series learned a lot and I will suggest you watch the recursion series by Aditya Verma and do a backtracking problem from the interview bit before starting this dp series it will help you a lot Topics covered in this series- 1)0/1 knapsack 2)unbounded knapsack 3)Longest common subsequence(LCS) 4)Matrix Chain Multiplication(MCM) 5)dp on trees Some interesting problems covered 1) Scrambled Strings 2)egg drop problem 3)Maximum Path sum from any node to any node 4)Minimum difference of subset-sum partition of an array
@bikrantanand1811
@bikrantanand1811 4 жыл бұрын
completed whole series..in the very first video u said main jaisa padhaunga koi nhi padhayega..guess u were right.......thanks
@Shri_2002
@Shri_2002 4 жыл бұрын
Bhai aapne bola tha saare variations padhayenge please complete kare isko isse pyaari series kahi nahi h youtube pr..
@factsbyalok
@factsbyalok 4 жыл бұрын
Bro Please, make a playlist on Graph. It will really helpful for us.
@laraibanwar1618
@laraibanwar1618 3 жыл бұрын
check take u forward you tube channel grapg series.. u will be good to go
@aayushtalesara9159
@aayushtalesara9159 4 жыл бұрын
Sir, thank you very much for such a great explanation. Please provide at least the problem statement's link of remaining questions which you discussed initially like.. Fibonacci(7) Lis(10) Kadane's Algorithm (6)
@ViralAgrawal12321
@ViralAgrawal12321 4 жыл бұрын
please sir complete it please
@thinkingmad1685
@thinkingmad1685 2 жыл бұрын
Aditya bro sachi me bohot confidence mila yaar , sabhi ko achese code kiya hu bohot acha tarikha tha thankyou 😃😃, Fir aaunga revision karne keliye 🙏🙏
@yashsharma788
@yashsharma788 Жыл бұрын
Hi, Found this on Google. Hope this help. These are few of the dp patterns along with problems of that particular pattern. Kadane's Algo: 1.Maximum difference of 0's and 1's in a binary string 2.Maximum Sum Circular array 3.Smallest sum contiguous subarray 4.Largest sum increasing contiguous subarray 5.Maximum Product Subarray 6.Largest sum contiguous subarray with only non-negative elements. 7.Largest sum contiguous subarray with unique elements. 8.Maximum Alternating Sum Subarray 9.Maximum Sum Rectangle In A 2D Matrix LIS: 1.Maximum Sum Increasing Subsequence 2.Print LIS 3.Best Team with No Conflicts (LC 1626) 4.No of LIS 5.Increasing Triplet Subsequence 6.LIS having sum almost K 7.Minimum Number of Removals to Make Mountain Array Inspired by Aditya Verma (youtube) Comment if you have other problems to add.
@zero-w1b
@zero-w1b Жыл бұрын
best playlist for beginners to advance
@codestorywithMIK
@codestorywithMIK 4 жыл бұрын
Something's wrong with this solution. But with such a good explanation, I figured it out . Thanks
@adityaagarwal637
@adityaagarwal637 4 жыл бұрын
I think ans variable is wrong, right?
@ShivamKumar-hh9pg
@ShivamKumar-hh9pg 2 жыл бұрын
Those who are stuck on Gfg. Try this: int solve(Node* root, int &res){ if(root==NULL) return 0; if(root->left == NULL && root->right == NULL) return root->data; int l = solve(root->left, res); int r = solve(root->right, res); if(root->left==NULL) return (root->data+r); if(root->right==NULL) return (root->data+l); int temp = max(l, r) + root->data; int ans = l+r+root->data; res = max(res, ans); return temp; } int maxPathSum(Node* root) { if(root==NULL) return 0; if(root->left==NULL && root->right==NULL) return root->data; int res = INT_MIN; int x = solve(root, res); if(root->left==NULL || root->right==NULL) return max(res, x); return res; }
@kiranjeetkaur4955
@kiranjeetkaur4955 2 жыл бұрын
can u plz tell why aditya verma code not working ,, left right null is checked in aditya code too .. i cant analyse whats main difference
@codetochange8
@codetochange8 2 жыл бұрын
It was a very nice journey with you Aditya ...I enjoyed this playlist thoroughly. Lots of appreciation for your hard work...Thankss😊
@ankitdubey9310
@ankitdubey9310 3 жыл бұрын
aditya bhai bahut badhiya playlist thi yaar 🎉🎉
@abdurrahmankhan6444
@abdurrahmankhan6444 4 жыл бұрын
Bhai baaki video bhi upload kar do iss playlist ki, dua milegi bachchon se jo abhi tak taras rahe hain DP ki complete series ke liye.... Itna delay na kar bhai, continuation mein break lag jata hai,,, Thanks for your efforts, till now best(est) DP series, but sadly incomplete...
@xCommandoEdits
@xCommandoEdits 2 жыл бұрын
Finally completed this playlist 😊
@vaibhav2863
@vaibhav2863 Жыл бұрын
series done sir dil se pranaam bhaiya
@jyotipal7821
@jyotipal7821 3 жыл бұрын
Finally today i complete this series...,i learnt lots of things from here... thanks alot aditya
@DragoonBlod
@DragoonBlod 4 жыл бұрын
We all understand that you cannot devote your time in making more videos at a regular pace, so it's a request to provide us with a basic list of topics that you left from the mentioned list in the beginning and list the variations under them. It'd be very helpful to be able to observe patterns in questions.
@093_danishnawab8
@093_danishnawab8 Жыл бұрын
Thanx for such efforts and great explaination! finally Completed it today!
@Imajay204
@Imajay204 Жыл бұрын
I completed full playlist..... Thank you Aditya Verma sir for such a wonderful content.❤️❤️
@lostgen36
@lostgen36 4 жыл бұрын
0:00 what a way to start off the video 🔥🔥
@rahulnagwanshi2348
@rahulnagwanshi2348 3 жыл бұрын
he has his own way of flexing
@kirtidhanai6772
@kirtidhanai6772 4 жыл бұрын
Literally the BEST SERIES OF TREEES that I've ever seeeen. Please make some on LINKED LIST, ARRAY QUEUE as well🥺 I AM SHOOK BY HOW EASY YOU MADE THIS PARTICULAR DS FOR ME. More power to youuuuu🙌🏻
@ritikshukla6062
@ritikshukla6062 4 жыл бұрын
Great that someone recommended this to u
@kirtidhanai6772
@kirtidhanai6772 4 жыл бұрын
@@ritikshukla6062 THANNNKKKYOUUUUU YOU
48 Diameter of a Binary Tree
15:13
Aditya Verma
Рет қаралды 128 М.
49 Maximum Path Sum | From any node to any node
12:16
Aditya Verma
Рет қаралды 116 М.
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН
43 Egg Dropping Problem Recursive
30:10
Aditya Verma
Рет қаралды 169 М.
L17. Maximum Path Sum in Binary Tree | C++ | Java
17:50
take U forward
Рет қаралды 363 М.
Maximum Sum Subarray of size K | Sliding Window
23:42
Aditya Verma
Рет қаралды 333 М.
L26. Print Root to Node Path in Binary Tree | C++ | Java
11:00
take U forward
Рет қаралды 218 М.
Max Sum Path in Binary Tree #InterviewBit Binary Tree Most Asked
9:49
Code with Alisha
Рет қаралды 6 М.
10 Minimum Subset Sum Difference
46:41
Aditya Verma
Рет қаралды 395 М.
39  Evaluate Expression to True  Boolean Parenthesization Recursive
40:00
1 Heap Introduction and Identification
22:25
Aditya Verma
Рет қаралды 322 М.
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН