Some error occured while loading page for you. Please try again.
You are viewing a single comment's thread. Return to all comments →
Test case 2 is failing for me!! In case of A being parent of B, I've returned A.
Here's my code:
def lca(root, a, b):
node = root
if max(a, b) < node.data:
node = node.left
elif min(a, b) > node.data:
node = node.right
Does that help you?
I noticed people often see @RubenzZzZ's anwser (which is awesome, btw) and forget to +1 this one too... Non-recursive == less expensive!