Binary Search Tree : Lowest Common Ancestor

  • + 0 comments

    Simple cpp solution

    		// Write your code here.
           int temp1=v1;
           int temp2=v2;
           v1=min(temp1,temp2);
           v2=max(temp1,temp2);
            if(v1<root->data && v2>root->data){
                return root;
            }
            else{
                if(v1>root->data){
                    return lca(root->right,v1,v2);
                }
                else if(v2<root->data){
                    
                   return lca(root->left,v1,v2); 
                }
            }
            return root;
        }