We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//check if root goes through vertex vboolpassBy(Node*root,intv){if(root==nullptr)returnfalse;if(root->data==v)returntrue;returnpassBy(root->left,v)|passBy(root->right,v);}Node*lca(Node*root,intv1,intv2){if(passBy(root->left,v1)&&passBy(root->left,v2))returnlca(root->left,v1,v2);elseif(passBy(root->right,v1)&&passBy(root->right,v2))returnlca(root->right,v1,v2);elsereturnroot;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
C++ Sol: I'm not sure if the given problem has all the properties of BST