Binary Search Tree : Lowest Common Ancestor

  • + 0 comments

    I don't think it is a correct solution.. It will always return the root of tree after final evaluation.. All test cases except test case 2 are working becuase fro all of them root of the tree is the LCA..

    Node lca(Node root,int v1,int v2){
        return root;     
     }
    

    Try this, you will know what I am trying to say.. If you run the above code it will also fail only test case 2..

    After we get the required node, in the shrinking phase of recursions we need a way so that we can contain the deepest recursive node in root and not the actual root of tree.. though I am not sure how to do that..