L53. Largest BST in Binary Tree

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น • 347

  • @takeUforward
    @takeUforward  3 ปีที่แล้ว +275

    This is the last video of this series. I hope you enjoyed this. Just a small request:
    “Please share the series, also you can tag me at Linkedin if you want a give a review for this series, this will do me a world of good”
    Thankyou 🙏🏻

    • @yash0270
      @yash0270 3 ปีที่แล้ว +2

      Thanks for creating this series.

    • @akhilesh59
      @akhilesh59 3 ปีที่แล้ว +6

      Thank you Bhaiya for this Wonderful series. It was the best DSA based series for me so far. I have already recommended this to all my friends. Now going to start the Graph series 😁..

    • @sejalrai7358
      @sejalrai7358 3 ปีที่แล้ว

      completely Lovedd this seriess!! thanks a lotttt

    • @krishnarajs929
      @krishnarajs929 2 ปีที่แล้ว

      Thanks bro , It was absolutely great...

    • @vaibhavkumar526
      @vaibhavkumar526 2 ปีที่แล้ว

      Hi I feel like the base case value is incorrect, lets say when root is Null, then my tuple returned should have maxNode as -infinity and minNode as +infinity. Then only lets say for a leaf node we can have a value of 1, as a single node is also a BST. Please check this. I tried dry running the code and it didn't work, so I thought I should share this. Well I might be wrong, so please cross verify.
      I can prove this, lets say, the leaf node is 10, so from the left side the max value would be -infinity and from the right side min value would be +infinity and hence the condition -infinity < 10 and 10 < + infinity would satisfy

  • @subodh.r4835
    @subodh.r4835 2 ปีที่แล้ว +343

    CONGRATS to everyone else who successfully completed this playlist!

    • @kushagraahire1871
      @kushagraahire1871 ปีที่แล้ว +1

      Did you get a job after learning DSA?

    • @ultimategyani6412
      @ultimategyani6412 ปีที่แล้ว +16

      ​@@kushagraahire1871 yes I got a full stack developer internship in Lockheed Martin( remote ).
      They asked me two DSA ques in technical round
      Print spiral matrix
      Lowest common subsecuence using DP

    • @kushagraahire1871
      @kushagraahire1871 ปีที่แล้ว +2

      @@ultimategyani6412 congratulations

    • @ultimategyani6412
      @ultimategyani6412 ปีที่แล้ว

      @@kushagraahire1871 thanks brother

    • @horccruxxxop4184
      @horccruxxxop4184 ปีที่แล้ว +1

      @@ultimategyani6412 what were your projects?

  • @arpanbanejee5143
    @arpanbanejee5143 3 ปีที่แล้ว +191

    Completed the entire FREE KA TREE series! Learnt a lot! Thank you Striver for putting up such quality content!

  • @bhargav1811
    @bhargav1811 ปีที่แล้ว +59

    11:27 Minimal will be 30 and not 40 !! Thank you striver for this series!! Helped me alot !!

    • @Area-fd8ht
      @Area-fd8ht ปีที่แล้ว

      ​@@namashsharma7550tum toh lodu ho fir..😂

  • @sujoyseal195
    @sujoyseal195 2 ปีที่แล้ว +52

    Correction : At 11:30 , the minimum for subtree with root=40 is 30 not 40 . Please provide an edit at this juncture

  • @PrinceTripathi-j7u
    @PrinceTripathi-j7u 11 หลายเดือนก่อน +7

    Completed the Tree series in 10 days.
    Thank you STRIVER for making such a quality content .

  • @DivyamPadole
    @DivyamPadole 23 วันที่ผ่านมา +2

    9:37 ,at root =14 , he wrote [size,max,min] and at root=18 ,he wrote [size,min,max] so dont confuse he suffle the order take order [size,max,min] max come form right size and min come for left size for creating a [size,max,min]

    • @imKushGupta
      @imKushGupta 10 วันที่ผ่านมา

      thanks man!!

  • @abdulrazzak2934
    @abdulrazzak2934 3 ปีที่แล้ว +46

    finally completed this amazing free ka tree series and now im taking a break then soon i'll start the next your graph series
    thanks alot striver for amazing explanation,efficient code ,time complexity an all.thank you so much

  • @Tahirkhan-hv3jn
    @Tahirkhan-hv3jn ปีที่แล้ว +6

    **important** if someone is confused while doing dry runwith the solution and example then consider this, There is issue in naming of variables in the code, even though things work well. The maxNode should be replaced by minNode and vice-versa.

  • @aaqilkrishna
    @aaqilkrishna ปีที่แล้ว +5

    Just completed this playlist and I would highly recommend it to anyone wanting to learn how to solve Binary Tree and Binary Search Tree based problems from scratch. Thank you for this valuable content !! Cheers ✌❤

  • @shobhitshrivastav9775
    @shobhitshrivastav9775 2 ปีที่แล้ว +20

    Today I have completed the Free Ka Tree series playlist .It took almost 21 days to complete this series from start to end .I really enjoyed the playlist and learn many new ways of solving tree questions ...thanku striver bhaiya for this top quality content always be thankful to you❤️❤️

  • @AkashDeep-jp1ts
    @AkashDeep-jp1ts 6 หลายเดือนก่อน +2

    The hardest tree question I came across but thanks to you, now it's completely clear!!

  • @noone-pn7yu
    @noone-pn7yu ปีที่แล้ว +5

    completed whole playlist today, thank striver

  • @Dontpushyour_luck
    @Dontpushyour_luck ปีที่แล้ว +2

    completed the entire tree series. Enjoyed a lot! thank you for all the content striver!

  • @jagjiwanchimkar8106
    @jagjiwanchimkar8106 3 ปีที่แล้ว +39

    Mistake at 11:28 , For 40, smallest will be 30 not 40

  • @taranjotsingh7780
    @taranjotsingh7780 2 ปีที่แล้ว +15

    Completed the entire series today. Feeling much more confident now. Thank you very much Stiver! 😃

  • @iamnoob7593
    @iamnoob7593 9 หลายเดือนก่อน

    Done with free ka tree series. A big thank you striver , I taught i knew trees very well , But when i watched these videos , I had not known most of it.

  • @vaishnavigour5777
    @vaishnavigour5777 2 ปีที่แล้ว +47

    completed this series today! THANKYOU STRIVER for making such a quality content . Really helped a lot . It took me 6 days to complete this series . It was worth it.

    • @kartiksrivastava3897
      @kartiksrivastava3897 2 ปีที่แล้ว +10

      currently watching the last video it took me 14 days.

    • @codding32world50
      @codding32world50 2 ปีที่แล้ว +5

      like how many videos per day

    • @parthsalat
      @parthsalat 2 ปีที่แล้ว +7

      Did you save/write the codes somewhere, like in a notebook or notion? Because storing codes takes up a lot of my time.

    • @vaishnavigour5777
      @vaishnavigour5777 2 ปีที่แล้ว +3

      Yes @parth I have noted them down in a notebook...not the full code but just the pseudo code

    • @parthsalat
      @parthsalat 2 ปีที่แล้ว +4

      @@vaishnavigour5777 Great! After consulting my "smart" friends, I too have decided to save codes only for difficult questions. For normal questions, I'll just jolt them down in a paper.

  • @aadityakhetan956
    @aadityakhetan956 3 ปีที่แล้ว +22

    A great series to learn tree from scratch. Thanks for top notch content. It was really very helpful.

  • @_CSE_PRATHISWARANGR
    @_CSE_PRATHISWARANGR ปีที่แล้ว +1

    Just completed your amazing tree series Striver and thanks for making such a wonderful series for free :)

  • @captcha14
    @captcha14 ปีที่แล้ว +8

    Earlier trees and graphs haunt me. Completed this playlist and now questions are solvable. Thank you striver.

    • @closetoheart6120
      @closetoheart6120 ปีที่แล้ว

      bhai are these playlist to understand concept easily ?? and is whole DSA complete here ?

    • @pushkarchoudhary8276
      @pushkarchoudhary8276 ปีที่แล้ว

      @@closetoheart6120 tree playlist are awesome u can follow this according to me

  • @Manishgupta200
    @Manishgupta200 ปีที่แล้ว

    This series is superb. Understood all series problem with proper Dry run and solved in multiple ways from Brute to Better to Optimal. Apart from that solved logical tree problem by myself.. Digonal traversal, Path Sum, Sum tree.. and going on..

  • @lifegood6401
    @lifegood6401 3 ปีที่แล้ว +19

    It is such a Great Series. More power to Striver. You are the superhero of students like us.

  • @imPriyansh77
    @imPriyansh77 9 หลายเดือนก่อน

    This is one of the best videos of the playlist !!! Thanks Striver bhaiya :)) You made trees easier to understand & visualize...

  • @kumarshreyas7899
    @kumarshreyas7899 2 หลายเดือนก่อน

    Thanks Striver for this incredible Tree Series , have learnt a lot from this series , and now I am gonna checkout Graph series.

  • @ashutoshpandey904
    @ashutoshpandey904 2 ปีที่แล้ว +7

    Finally, Completed this entire series and learnt a lot!
    It took me around 3 weeks to complete this series and it's totally worth it.
    Thank you Striver for such quality content, Really helped me a lot !❤❤

  • @golubhattuk01
    @golubhattuk01 หลายเดือนก่อน

    finally today 06/11/2024 i have completed this playlist .. during this period i had my exams too , i got sick for 1 week so i didn't study for 1 week thank you striver for this amazing series

  • @URadityaaaaa
    @URadityaaaaa 6 หลายเดือนก่อน +3

    **Correctionss
    if(root==NULL)
    return {INT_MIN,INT_MAX,0};
    if(root->data>left.mx && root->datadata,right.mx),min(root->data,left.mn),1+right.n+left.n};
    }
    else
    {
    return {INT_MAX,INT_MIN,max(left.n,right.n)};
    }

  • @ashishpradhan6250
    @ashishpradhan6250 4 หลายเดือนก่อน

    another playlist completed.. thanks for bringing a change in other's lives

  • @arghya_0802
    @arghya_0802 2 ปีที่แล้ว +2

    Completed the entire Tree Series. The best one without a doubt!! Finished all the questions & will probably do a couple more. The next destination is DP !!

  • @AngadSingh97
    @AngadSingh97 2 ปีที่แล้ว +3

    Hi everyone
    The link from the SDE SHEET links to Maximum Sum BST in Binary Tree, whereas Striver has solved for Largest BST in Binary Tree.
    I did not read the question description correctly and was using the approach for the wrong question. Please be careful so that you don't waste 30 minutes like I did, debugging the code and wondering why it's not working.
    Good to reach the end of Tree Series, thank you Striver bhai. Now on to Graph and DP Problems : ).

  • @rishabhgupta1222
    @rishabhgupta1222 6 หลายเดือนก่อน

    Just completed the Tree series playlist....absolutely mindblowing content with highest level of perfection !!!!

  • @mohammedraiyaan-bt6iy
    @mohammedraiyaan-bt6iy 4 หลายเดือนก่อน

    Thanks sir , Because of you another topic of dsa is completed.

  • @DivyamPadole
    @DivyamPadole 23 วันที่ผ่านมา +1

    when null occur do min=MAX INTEGER and max=MIN INTEGER |||||||||||||| Range is not follow the rule the max=MAX INTEGER AND min=MIN INTEGER 😉

  • @divyamgupta-t3i
    @divyamgupta-t3i ปีที่แล้ว +3

    Can this approach work, not wrt TC, but the intuition only ?
    1. Find Inorder of binary tree and store it in vector
    2. Find the largest sorted substring in that vector
    Considering each element in tree is unique.

    • @selvamani.kannan
      @selvamani.kannan 9 หลายเดือนก่อน

      yes, it should work.
      length of longest increasing sub array

    • @SameerRehan-tt4lh
      @SameerRehan-tt4lh 7 หลายเดือนก่อน

      no

    • @dank7044
      @dank7044 6 หลายเดือนก่อน +1

      It won't work,because we need to return a node as an ans. so the ans would be the complete tree,originating from that node,you cant selectivel keep or exclude any of its child,by your method, you might do this

    • @karthik-varma-1579
      @karthik-varma-1579 2 หลายเดือนก่อน

      i Came up this approach first when I seen the question

  • @gouravkushwaha68
    @gouravkushwaha68 ปีที่แล้ว

    Completed this amazing free ka tree series today

  • @tejassrivastava6971
    @tejassrivastava6971 3 ปีที่แล้ว +7

    solution with cam makes more easier to understand the concept. Thanks!

  • @ravalikatalks5285
    @ravalikatalks5285 21 วันที่ผ่านมา

    Thanks tou striver for whole series👐✨

  • @HEMANTPORWAL-t7d
    @HEMANTPORWAL-t7d 5 หลายเดือนก่อน +3

    495k to 137k itself speaks many things
    well done striver bhaiya

  • @MdArman_cs
    @MdArman_cs ปีที่แล้ว

    Finally i successfully completed the free ka tree series thanks striver bhaiya🧡

  • @LBK3
    @LBK3 2 ปีที่แล้ว +2

    Whole tree series is absolutely amazing
    used to have a lot of confusion on trees and pointers used in them...
    Completely cleared thanks alott Striver❤

  • @Himanshhhhxu
    @Himanshhhhxu 7 วันที่ผ่านมา

    This series is also completed ❤🎉 done and dusted

  • @shirishprataya4602
    @shirishprataya4602 2 ปีที่แล้ว

    Finally completed this series. Thanks a lot Striver. You have helped a lot. This truly was the best tutorial on trees. 🔥🔥🔥

  • @PrateekJesingh
    @PrateekJesingh 3 ปีที่แล้ว +6

    Thanks!

    • @PrateekJesingh
      @PrateekJesingh 3 ปีที่แล้ว

      @takeUforward @striver Loved the entire tree series!

  • @tanmaychaudhary2801
    @tanmaychaudhary2801 ปีที่แล้ว +2

    In starting i have got fear from tree topic...and vertical order traversal topic was demotivating for me because at that time I was thinking this(tree and DSA) is not for me....but I continued it and striver bhaiya made it very easy to understand all the topics and now I am feeling very much familiar with this topic...now I am able to think for solutions by myself....thanks a lot striver bhaiya...❣️💫🙌😊🙏

  • @sautramanivibhuti4597
    @sautramanivibhuti4597 ปีที่แล้ว

    Finally completed
    Thanks striver bhaiya
    You owe my respect 📈❤️

  • @deepaksaini3986
    @deepaksaini3986 2 ปีที่แล้ว +2

    Completed successfully!! Now revision is the only thing to do !! and will do it!!

  • @parthsalat
    @parthsalat 2 ปีที่แล้ว +2

    Thanks for the series...I'd have never learnt BST if it wasn't for this series

  • @abhijeetanand3443
    @abhijeetanand3443 2 ปีที่แล้ว +6

    woho finally reached here, thankyou so much striver (Sir/Bhaiya) for this playlist. Many will come through all videos till here and each time you will be blessed by tons 🙌🤩

  • @saurabhgautam2697
    @saurabhgautam2697 2 ปีที่แล้ว +5

    Completed the whole series ,I was kindaa slow ,took me 3 weeks-1 month,but understood the concepts very well ,as you always say straight into the mind
    Thankyou bhaiya

  • @Nikita-hv5jm
    @Nikita-hv5jm 2 ปีที่แล้ว +2

    finallyy completed the whole series....thanks a lot striver for such a wonderful series on tree...💫

  • @prateek4-yearb.tech.chemic511
    @prateek4-yearb.tech.chemic511 2 ปีที่แล้ว +2

    I CAN CONFIDENTLY SAY THAT THIS IS THE ABSOLUTE BEST SERIES ON TH-cam FIR TREES; LAST QUESTIONS WERE JUST TOP NOTCH . LOVED IT THANKS STRIVER .

  • @sunnykumarsingh7039
    @sunnykumarsingh7039 2 ปีที่แล้ว +7

    Today complete the SDE sheet. This was the last question I attempted.
    Yeah, the order in which I did was according to my comfort,
    Nevertheless, your content is LIFE-SAVER!!

  • @hasini7441
    @hasini7441 2 หลายเดือนก่อน

    Loved the series ❤ thank you

  • @HarshKumar-ip5nr
    @HarshKumar-ip5nr ปีที่แล้ว +2

    Just an approach. What if we do inorder traversal and find the index of points that violate the increasing vector. Now, we have simultaneously calculated the size of each seperate BST in inorder traversal and return the max one. i.e. suppose the iteration was like: 2, 3, 4, 5, 1, | 6, 7, 8, 10, 12, 13, 9 | 20, 21.. The sizes are : 5, 7, 2 and we return 7. Any thoughts and code?

    • @sarthakragwan5248
      @sarthakragwan5248 ปีที่แล้ว

      This approch fails i also did this one

    • @HarshKumar-ip5nr
      @HarshKumar-ip5nr ปีที่แล้ว

      @@sarthakragwan5248 why, can you give some insight

    • @dank7044
      @dank7044 6 หลายเดือนก่อน

      @@HarshKumar-ip5nr
      It won't work,because we need to return a node as an ans. so the ans would be the complete tree,originating from that node,you cant selectivel keep or exclude any of its child,by your method, you might do this

  • @pavannettam8968
    @pavannettam8968 ปีที่แล้ว +4

    The playlist was really helpful to understand trees, thank you so much @striver. I'm sure this is the best tree playlist in the market.

  • @huungryyyy
    @huungryyyy 5 หลายเดือนก่อน

    bhai kitna pyaara soln likha hai 😍

  • @momilijaz271
    @momilijaz271 2 ปีที่แล้ว +7

    I am in love with this amzing content, definitely gonna follow all other playlists and striver's sheet. Can;t thank you enough for the great content.!

  • @varnit1975
    @varnit1975 2 ปีที่แล้ว +3

    At size 4 the minimal should be min(40,30) = 30 not 40

  • @ruturaj_dm
    @ruturaj_dm 11 หลายเดือนก่อน +2

    I m not sure how is this solution a O(1) space complexity. We are creating and returning NodeValue object from each node. So for all the O(N) nodes we are returning a new object. If every object is assumed to take O(1) space then we have O(N)*O(1) = O(N) space.

    • @pqrstwxyz1175
      @pqrstwxyz1175 11 หลายเดือนก่อน +1

      Same doubt...did you get any explanation?...surely has to be O(N)

  • @stith_pragya
    @stith_pragya ปีที่แล้ว

    Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @mayankbisht1277
    @mayankbisht1277 2 หลายเดือนก่อน

    Very good concept

  • @gouravkumar7459
    @gouravkumar7459 3 ปีที่แล้ว +2

    Thanks for this amazing playlist, though I knew trees and have done a lot of questions on it, still I wanted to learn new approaches, indeed I learned amazing approaches. Thanks again. :)

  • @shantipriya370
    @shantipriya370 11 หลายเดือนก่อน

    completed the list.. thank you so much..

  • @gsmdfaheem
    @gsmdfaheem 2 ปีที่แล้ว +1

    Finally completed the entire Free Ka Tree Series....Thank you so much striver bhaiya for putting in all the efforts...You are the best.

  • @parthsalat
    @parthsalat 2 ปีที่แล้ว +3

    9:25 FIrst 19 will come then 16 will come

  • @DSRhymster
    @DSRhymster 2 ปีที่แล้ว

    Completed the whole tree series today.... Learnt alot thank you Striver the saviour 🥰🥰

  • @abhirupbasu3386
    @abhirupbasu3386 ปีที่แล้ว +1

    Completed the tree series.Thanks for making this amazing tree series.

  • @rishabhgupta9846
    @rishabhgupta9846 ปีที่แล้ว +1

    Completed the series in 2 weeks ,thank you Striver for such wonderful playlist.

  • @sandeep-sb
    @sandeep-sb ปีที่แล้ว

    Completed the Free ka Tree Series today. Thank you, Striver. I learned a lot from this series. Onto the next one :)

  • @sulakshGaming
    @sulakshGaming 11 หลายเดือนก่อน

    amazing explanation, thanks!

  • @muditkhanna8164
    @muditkhanna8164 ปีที่แล้ว +1

    using the similiar approach here is the code for the maximum sum BST Leetcode 1373
    /**
    * Definition for a binary tree node.
    * struct TreeNode {
    * int val;
    * TreeNode *left;
    * TreeNode *right;
    * TreeNode() : val(0), left(nullptr), right(nullptr) {}
    * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
    * };
    */
    int ans; //ans declared globally
    class bstnode{
    public:
    bool valid;
    int maxl;
    int minr;
    int sumtotal;
    bstnode()
    {
    valid=true;
    maxl=INT_MIN;
    minr=INT_MAX;
    sumtotal=0;
    }
    };
    class Solution {
    public:
    bstnode calc_sum(TreeNode*root)
    {
    if(root==NULL)
    {
    return bstnode();
    }
    bstnode curr;
    bstnode left=calc_sum(root->left);
    bstnode right=calc_sum(root->right);
    //why max left and min right
    //well the highest max in left should be less than root->val and the lowest value in right should be less than root->val in order for it to be a bst
    //if the bst 's right and left are valid and maxleftvalvalval;
    //these next two steps are generally done for the recursion part
    //otherwise there's not much need after getting to know that it is a bst
    //as we are finding from bottom to root
    //the right min value will be compared with the right's left and right->val for min
    curr.minr=min(root->val,left.minr);
    //the left max value will be compared with the left's right and left->val for max
    curr.maxl=max(root->val,right.maxl);
    }
    else
    { //else make it false and the sum of that non bst will be either from right or left
    //because together left and right with node cannot be a bst so the right and root or left and root
    //will make bst, that's why taking the max of them
    curr.valid=false;
    curr.sumtotal=max(left.sumtotal,right.sumtotal);
    }
    //with every recursive call ans is updated we'll wait till the base condition and keep updating answer
    ans=max(ans,curr.sumtotal);
    //the return value is the valid bst for this recursive function
    return curr;
    }
    int maxSumBST(TreeNode*root)
    {
    ans=0;
    calc_sum(root);
    return ans;
    }
    };

  • @fazilshafi8083
    @fazilshafi8083 4 หลายเดือนก่อน

    Thank you! 🔥

  • @vaibhav5269
    @vaibhav5269 9 หลายเดือนก่อน

    Hi Striver, Thanks for the free tutorials. I had a small doubt in this problem: If we just exclude 17 from the tree , the remaining tree is a BST, then the size would become 10. Why dont we solve it in this way, It is also a subtree right?

  • @AyushiSingh-iy5uf
    @AyushiSingh-iy5uf ปีที่แล้ว

    Merge two BSTs is missing in this series, please upload that too! Thanks in advance :)

  • @mdrehankhan3458
    @mdrehankhan3458 ปีที่แล้ว

    Thanks man!!
    this series really helped me to solve tree problems which I found quite difficult while l solving tree questions.

  • @OmPrakash-kb2wq
    @OmPrakash-kb2wq 2 ปีที่แล้ว +1

    Thank you so much striver. I learnt a lot from this series. Earlier I have very low confidence in Tree and now after your series and practice I leave become very much confident in this portion.

  • @vivekchatterjee4001
    @vivekchatterjee4001 2 ปีที่แล้ว

    Completed the Series today, developed logic, and made notes, next is the Graph series. Journey never ends✌✌

  • @srinivasveligethi2380
    @srinivasveligethi2380 ปีที่แล้ว

    @11:27 I Guess minimal should be 30 instead of 40 becuase root should be less than or equal to minimal of right sub tree.

  • @YashveerGahlot-t6b
    @YashveerGahlot-t6b 4 หลายเดือนก่อน

    thank u so much sir !!!!
    it will help me

  • @____Akash__
    @____Akash__ ปีที่แล้ว +5

    Time Complexity O(N^2) and sc O(1)
    class Solution{
    public:
    //the brute force approach is first i'll check for every node if this node
    // is a root of a bst or not if this node contains bst then we cnt the size
    //time complexity O(N^2)
    bool isValidBST(Node* root,int min, int max){
    if(root == NULL) return true;
    if(root->data < min || root->data > max){
    return false;
    }
    return isValidBST(root->left, min, root->data) && isValidBST(root->right, root->data, max);
    }
    int countNode(Node* root){
    if(root == NULL) return 0;
    if(!root->left && !root->right) return 1;
    int left = countNode(root->left);
    int right = countNode(root->right);
    return left + right + 1;
    }
    void checkNode(Node* root, int &maxi){
    if(root == NULL) return;
    if(!root->left && !root->right) return;
    if(isValidBST(root,INT_MIN,INT_MAX) == true){
    int cnt = countNode(root);
    maxi = max(cnt, maxi);
    }
    checkNode(root->left, maxi);
    checkNode(root->right, maxi);
    }
    int largestBst(Node *root)
    {
    int maxi = 1;
    checkNode(root, maxi);
    return maxi;
    }
    };

  • @arpitagupta5834
    @arpitagupta5834 2 ปีที่แล้ว +1

    In the first example, why isn't 10 included in the BST? (10,5,1,8)

  • @asit7456
    @asit7456 2 ปีที่แล้ว +1

    Could you please give notes of the tree series it is incomplete as the notes and the effective explanation makes the series effective.

  • @youracademicfriend-shashwa1051
    @youracademicfriend-shashwa1051 5 หลายเดือนก่อน

    Thankyou
    Great Explanation!!

  • @Nintendo04
    @Nintendo04 2 ปีที่แล้ว

    finaly completed the entire series and got good concept of tree , thank you for quality content!

  • @kashishsharma6809
    @kashishsharma6809 3 ปีที่แล้ว +1

    i like brute force also, putting memorization for sub branches.

  • @DeadPoolx1712
    @DeadPoolx1712 หลายเดือนก่อน

    UNDERSTOOD;

  • @sarthakkapoor3764
    @sarthakkapoor3764 3 ปีที่แล้ว +2

    How many more episodes left in the tree series?

  • @kO_SE__ShivamKumar
    @kO_SE__ShivamKumar ปีที่แล้ว +2

    A really nice explanation again!!!

  • @saravana6882
    @saravana6882 2 ปีที่แล้ว +2

    // simple implementation using vector
    class Solution{
    int sum =0;
    public:
    vector maxSum(Node *root) {
    if(root == NULL)
    return {INT_MAX, INT_MIN, 0};
    vector l = maxSum(root->left);
    vector r = maxSum(root->right);
    if(l.size() == 0 || r.size() == 0|| root->data data >= r[0])
    return {} ;

    vector ans(3);
    ans[0] = min(root->data, l[0]);
    ans[1] = max(root->data, r[1]);
    ans[2] = root->data + l[2] + r[2];
    sum = max(sum, ans[2]);
    return ans;

    }
    int largestBst(Node *root)
    {
    maxSum(root);
    return sum;
    }
    };

    • @tusharnain6652
      @tusharnain6652 2 ปีที่แล้ว

      it got more space complexity/

  • @ayushdhiman8128
    @ayushdhiman8128 3 ปีที่แล้ว +1

    ky ye series yaha samaapt hoti hai? Thank you for this free playlist ❤

  • @Yag116
    @Yag116 ปีที่แล้ว +1

    Completed this playlist sucessfully

  • @the_witcherr275
    @the_witcherr275 5 หลายเดือนก่อน

    Easy to understand working code for python developers
    def largestBst(self, root):
    # Your code here
    def solve(node):
    if not node:
    return [float("inf"), float("-inf"),0]
    left = solve(node.left)
    right = solve(node.right)
    if left[1]

  • @ayobrrr
    @ayobrrr 5 หลายเดือนก่อน

    class Solution:
    def largestBst(self, root):
    def rec(node):
    if node:
    if not node.left and not node.right:
    return [True, node.data, node.data, 1]
    left = rec(node.left)
    right = rec(node.right)
    if left[0] and right[0] and left[2] < node.data < right[1]:
    return [True, min(left[1], node.data), max(right[2], node.data), left[3] + right[3] + 1]
    return [False, -1, -1, max(left[3], right[3])]
    return [True, math.inf, -math.inf, 0]
    return rec(root)[3]
    if someone needs python code -

  • @abhinavpandey3356
    @abhinavpandey3356 2 ปีที่แล้ว

    Is the complexity of brute is o(n^3) ie for passing every node to validate * validating *getting size if it is a valid BST ie o(n*n*n) ?please check

  • @mukeshmahajan1586
    @mukeshmahajan1586 3 ปีที่แล้ว

    mm mmm problem problem --striver...Loved it man! 9:50

  • @mmmm-wm8ci
    @mmmm-wm8ci ปีที่แล้ว

    In right subtree with root 40 how minnode is 40 instead of 30.

  • @navyaposham-hx6ix
    @navyaposham-hx6ix 5 หลายเดือนก่อน

    I dont understand we can just exclude 14&17 right?
    If we include 15,16,18,19,20,30,40,50,60 we get a bst of size 9 and that can be our answer

  • @codding32world50
    @codding32world50 2 ปีที่แล้ว +1

    Finally Compelted Yess it took me lot more time than expected... But it is with it.. Thank Youuu So much Striverrr

  • @sujan_kumar_mitra
    @sujan_kumar_mitra 3 ปีที่แล้ว +2

    Thanks for the series, it's really helpful.
    Waiting for your upcoming series.