Binary Search Tree : Lowest Common Ancestor

  • + 2 comments

    root->(right)->x->(right)->v1->(right)->v2

    Consider this. LCA is v1's address.But since you're returning only the address without storing it in some value,it is getting lost.When control gets to x it will return it's own root ie x because each parametrised "root" is local.However storing it in root updates the value of the local root with the LCA and as the chain of hierarchy goes upwards the LCA keeps getting returned.

    • + 0 comments

      great answer...

    • + 1 comment

      Hello, Can someone explain below scenario I have added below input in custom testcase for current program. 6 4 2 3 1 7 6 0 5 v1 =0 and v2 = 5 which are not present in my tree still it shows common parent as 4. and testcase shows pass.

      • + 0 comments

        Kindly follow the constraints while creating a custom testcase :)