Lowest Common Ancestor of a binary tree | Leetcode

Поділитися
Вставка
  • Опубліковано 24 сер 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!

  • @embarrassed_dodo
    @embarrassed_dodo 2 місяці тому

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

  • @amratef3245
    @amratef3245 Рік тому +1

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

  • @sirichandanayadav5249
    @sirichandanayadav5249 2 роки тому +1

    Happy teacher's day Sir...

  • @praveengautam4689
    @praveengautam4689 2 роки тому

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

  • @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!

  • @charkhude
    @charkhude 2 роки тому +4

    Thanks

  • @ritikmishra5210
    @ritikmishra5210 2 роки тому +2

    Man, you're awesome as always!

  • @anupam6045
    @anupam6045 2 роки тому

    Best expalnation ever

  • @albindavis3538
    @albindavis3538 Рік тому

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

  • @chrisliewjy
    @chrisliewjy 2 роки тому +2

    Great stuff! 👍🏻

  • @nurshuvo3854
    @nurshuvo3854 2 роки тому +1

    Great explanation.

  • @areebashaikh22
    @areebashaikh22 8 місяців тому

    Thank you!

  • @mangoman2023
    @mangoman2023 2 роки тому

    Very nice explanation. Thank you

  • @chetantailor3620
    @chetantailor3620 2 роки тому +1

    Nicely explained !!

  • @harpercfc_
    @harpercfc_ 2 роки тому

    THIS IS AWESOME.

  • @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.

  • @ui.ashish
    @ui.ashish 2 роки тому +2

    amazing content

  • @sharonwang592
    @sharonwang592 Рік тому

    Very smart! Thanks

  • @mrinalmadhav8119
    @mrinalmadhav8119 2 роки тому +1

    Very much excited

  • @devbhattacharya153
    @devbhattacharya153 2 роки тому

    Thanks a lot sir :)

  • @nitinsaxena1857
    @nitinsaxena1857 2 роки тому

    Excellent.

  • @santoshrathod9868
    @santoshrathod9868 2 роки тому

    Thanks brother

  • @preetambal7443
    @preetambal7443 2 роки тому +1

    Awesome!!

  • @JangBahadur3028
    @JangBahadur3028 2 роки тому +2

    Wait is over. 😊

  • @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

  • @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.

  • @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) ?

  • @biswajitmahato4413
    @biswajitmahato4413 2 роки тому

    What is the editor name?

  • @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