Lowest Common Ancestor of a Binary Tree
Difficulty: Medium
Acceptance: %
Points: 30.00
Given a Binary Tree with all unique values and two nodes value, n1 and n2. The task is to find the lowest common ancestor of the given two nodes. We may assume that either both n1 and n2 are present in the tree or none of them are present.
LCA: It is the first common ancestor of both the nodes n1 and n2 from bottom of tree.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(log n) for recursive calls.