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...
You're an excellent teacher, I've learned so much from your videos, you explain recursion beautifully, Thank you!
Awesome explanation, I had trouble understanding this earlier but now i get it
Great!
I don't comment very often on videos, but yours really helped me. Thank you so much
Welcome :)
Happy teacher's day Sir...
you explaied node tree recursion like a class 8th maths problem. Bro you're a genius.
Nice one. Please do Leetcode 621 - Task Scheduler.
Sure 👍🏼
@TECH DOSE, Yes! Please do 621! Thank you!
Thanks
Welcome :)
Man, you're awesome as always!
Thanks 😊
Best expalnation ever
great explanation theyw ay you explain the question by all possibe senario is superb
Great stuff! 👍🏻
Thanks ☺️
Great explanation.
Thanks :)
Thank you!
Very nice explanation. Thank you
Nicely explained !!
Thanks
THIS IS AWESOME.
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.
Yes I will 👍🏼
@@techdose4u thanks, looking forward to it!
👌🏼
amazing content
Thanks 😊
Very smart! Thanks
Very much excited
😀
Thanks a lot sir :)
Excellent.
Thanks brother
Awesome!!
Thanks
Wait is over. 😊
😀
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
Take some examples and it will be clear for sure
👏👏👏
~12.30 is wrong.LCA could have been 5 also . So the conclusion is wrong. I guess needs an edit.
Can you also discuss on side how to solve if links to parent is present (i.e each node contains link to parent) ?
Ok
What is the editor name?
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.
such an awful explanation