Тэги:
#lowest_common_ancestor #common_ancestor #binary_tree #binary_search_tree #linked_list #code #algorithm #program #parents #children #common_parents #siblings #interview #placement #information_technology #computer_science #first #common #ancestor #first_common_ancestorКомментарии:
Excellent explanation 👍
ОтветитьThis man is awesome. Thank you.
ОтветитьCan you please tell how is this inorder? Shouldn't it be preorder
ОтветитьWhat if the root node is one of the two node ??
ОтветитьExplain it for (j,c).... 🤨
ОтветитьI wonder when you first encounter this question, how do you figure out the possible steps for getting the answer? I am having trouble of algorithm questions recently. Very hard for me to think of the answer
ОтветитьI love this guy, very clear explanation !!!
ОтветитьGreat Video...
PS-: can watch it at 4x comfortably
Bahut badhiya sir .... Maja a Gaya sir
Ответитьcode doesn't work if one of the node is not present, ideally it should return null but it returns the other node which is found
ОтветитьThank you
ОтветитьLove you bro. You are so real!!
ОтветитьClear explanation. Easy to understand
Ответитьthe best!☺
Ответитьthank you
Ответитьmake more videos plzzzzzzzzzzz :(
ОтветитьThanks bro
Ответитьwell explained..
ОтветитьSir, I have watched many other people videos but your's are simply crystal clear
ОтветитьThe author is a genius. Thank you very much!
ОтветитьSir amazing explanation
ОтветитьIt would be far better if you also explain the intuition to this solution. Knowing the algorithm makes half of the work but knowing what led to this algorithm will make the solution video totally worthy.
Ответитьthis is how the DSA faculty looks like!
ОтветитьBest explanantion :) .Subscribed
ОтветитьIt's good
ОтветитьShould be pre-order instead of in-order.
ОтветитьGreat Video. Thank you sir. What happens in the case when there is only one value present in the tree, and the other value is not. In that case, the algorithm is not working.
ОтветитьNo need for "else". Great code walkthrough and explanation !
ОтветитьThis solution not work when one of the two nodes is found and not the second one. So its return the founded node.
ОтветитьAbsolutely love the clear explanation and walkthrough. Thank you!
ОтветитьOKK .. lets just appreciate his innocent smile!
Ответитьnice video.............................
Ответитьgreat explanation but i think this is pre order traversal
ОтветитьThanku ji
Ответитьthis solution will not work in case if B==root->node ans c is not present
Ответитьsir this is a very good explanation, just one point that you should have told that we are taking the assumption that both the nodes exist in the tree
ОтветитьThank you for your tutorial. You are one of the best so far. For the if(left !=null && right = null) return root. Is that right or (right !=null) .Please explain. Thank you very much.
Ответитьthanks for making things clear and simpler sir
ОтветитьSir ji, apka teaching ka FAN ho gya hu me to .. love you.
Some of the best things about your video,
1. your slow explanation.
2. code walk through
3. Complete explanation with lots of examples.
Ur a amazing teacher
Ответитьusually i have a hard and long time understanding these kinds of videos, but your videos are so clear I feel like even a toddler can understand
Ответитьso clear explanation!
Ответитьreally good method of explaining!!
ОтветитьThis won't work when one of the two nodes is not found.
ОтветитьHello, Thanks for explaining so well, In your logic for finding out LCA works fine if both the nodes are present and both the nodes are part of different sub tree. Two situation does not handle in this code. 1) if either of the node is not present in tree itself 2) if second node is part of subtree of first node. for exm, P and L nodes. If user enters these two nodes then this algorithm will not work.
Solution algorithm:
1) Both the nodes must present in tree otherwise print error and return.
2) if left and right returns non NULL, this is LCA. Print LCA and return NULL.
3) if second node is in subtree of first node then only first node we will return till root node. in such case main function shall have a piece of code, if final return is non NULL then this is the LCA, print LCA.
I can post the code if someone needs. thanks
DAMM !!! ABSOLUTLY SPOT ON
ОтветитьYou are the best teacher sir thank you so much for all this solutions
Ответитьtry this approach
struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {
if (p->val<root->val && q->val<root->val)
return lowestCommonAncestor(root->left,p,q);
if (p->val>root->val && q->val>root->val)
return lowestCommonAncestor(root->right,p,q);
return root;
}
i was not able to understand this question's solution from any other video but your simple explanation worked and i will never forget this solution again, thanks so much sir!
Ответить