Lowest Common Ancestor of a binary tree | Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ส.ค. 2024
  • This video explains a very frequently asked programming interview problem which is to find the lowest common ancestor in the given binary tree.I have first explained the problem statement followed by concepts of lowest common ancestor using examples and then finally showed 2 different ways to solve the problem. I have shown the first solution by finding the last common node in the root to node path. The second solution is based on simple recursion.
    CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ======================================PLEASE DONATE=============================
    🧡 SUPPORT OUR WORK: / techdose
    💚 UPI-ID: surya.kahar@ybl
    💞JOIN Membership: / @techdose4u
    ==============================================================================
    INSTAGRAM : / surya.pratap.k
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithT...
    TELEGRAM Group LINK: t.me/joinchat/...
    =======================================================================
    USEFUL LINKS:
    🟠Must do TIPS to ACE Virtual Interview: • 🔴Must do Tips to ACE y...
    🟢Best strategy to excel your coding interview: • 🔴Best strategy to exce...
    🟡Get your dream job in 1 month: • 🔴Get your dream job in...
    🔵How to crack dream job in just 2 months: • How to crack dream job...
    🟣7 Days DSA plan: techdose.co.in...
    RELATED LINKS:
    Vertical Order Traversal of Binary Tree: • Vertical order travers...
    Unique BSTs: • Unique Binary Search T...
    Count Complete Tree Nodes: • Count Complete Tree No...
    CODE LINK: gist.github.co...

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

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

    You're an excellent teacher, I've learned so much from your videos, you explain recursion beautifully, Thank you!

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

    I don't comment very often on videos, but yours really helped me. Thank you so much

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

    you explaied node tree recursion like a class 8th maths problem. Bro you're a genius.

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

    Awesome explanation, I had trouble understanding this earlier but now i get it

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

      Great!

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

    Happy teacher's day Sir...

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

    Nice one. Please do Leetcode 621 - Task Scheduler.

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

      Sure 👍🏼

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

      @TECH DOSE, Yes! Please do 621! Thank you!

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

    Man, you're awesome as always!

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

    Thanks

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

    TECH DOSE, do you plan to add playlists according to the Leetcode's difficulty level? That would increase views for you and help the audience to watch the whole list of problems that they target. Thanks.

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

      Yes I will 👍🏼

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

      @@techdose4u thanks, looking forward to it!

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

      👌🏼

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

    great explanation theyw ay you explain the question by all possibe senario is superb

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

    Great stuff! 👍🏻

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

    Best expalnation ever

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

    Very nice explanation. Thank you

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

    Great explanation.

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

    Nicely explained !!

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

    Thank you!

  • @ui.ashish
    @ui.ashish 2 ปีที่แล้ว +2

    amazing content

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

    THIS IS AWESOME.

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

    Very much excited

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

    Very smart! Thanks

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

    Thanks a lot sir :)

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

    Excellent.

  • @sunny-14689
    @sunny-14689 2 ปีที่แล้ว +1

    Can you also discuss on side how to solve if links to parent is present (i.e each node contains link to parent) ?

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

    Thanks brother

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

    Awesome!!

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

    Your final commentary is a lot confusing and doesn’t explain why you return left or right when the other is null. It is because when right is null you found both modes on left so the left node down is LCA and vice-versa

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

      Take some examples and it will be clear for sure

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

    What is the editor name?

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

    Wait is over. 😊

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

    👏👏👏

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

    ~12.30 is wrong.LCA could have been 5 also . So the conclusion is wrong. I guess needs an edit.

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

    This makes unnecessary work. Imagine that both nodes are on the left, your code still explores the entire right subtree, when it could already stop the search there. You can keep state locally in the class or use an helper method with an additional settable field to avoid this. On the other hand, the fact that you don't continue the search down the subtrees when root matches one of the nodes, reduces the search space, so depending on the case, it might end up being better or worse.

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

    such an awful explanation