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 is present.
n1 = 2 , n2 = 3
n1 = 3 , n2 = 4
Just complete the function lca() that takes nodes, n1, and n2 as parameters and returns LCA node as output.
Expected Time Complexity: O(N). Expected Auxiliary Space: O(H).
Note: H is the height of the tree.
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000