JuniorJunior (1–3 yrs)CodingPythonFacebookAmazonMicrosoft
Lowest Common Ancestor in BST
Find LCA of two nodes in a Binary Search Tree.
Answers use simple, clear English.
Audio N/ATime: O(h)Space: O(1) iterative
Quick interview answer
Walk from root: if both values are smaller, go left; both larger, go right; otherwise current node is LCA. O(h) time.
Detailed answer
Walk from root: if both values are smaller, go left; both larger, go right; otherwise current node is LCA. O(h) time.
juniormid#bst#tree