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.
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.
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.
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all 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.
great answer...
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.
Kindly follow the constraints while creating a custom testcase :)