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.
//O(h) - h is height of the binary search tree ----> O(log(n))//Worst case (Skewed BST): Height h = n -- O(n). Node*lca(Node*root,intv1,intv2){if(root==nullptr)returnroot;while(root){if(v1<root->data&&v2<root->data)root=root->left;elseif(v1>root->data&&v2>root->data)root=root->right;elsereturnroot;}returnroot;}
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++ `14 Solution: