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.
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(log n) for recursive calls.
Constraints:
1 <= number of nodes <= 10^5
1 <= node->data <= 10^5
Companies:
AmazonMicrosoftGooglePaypalCisco + 3 more
Topics:
Tree
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.