Skip to main content
Lowest Common Ancestor of a Binary Search Tree | AlgoCracked
AlgoCracked
ProblemsLowest Common Ancestor of a Binary Search Tree
Medium65.0% acceptance
Blind75TreeDfsBinary Search Tree

Lowest Common Ancestor of a Binary Search Tree

Given the root of a binary search tree and the values of two of its nodes p and q , find their lowest common ancestor (LCA) and return its value . The LCA of p and q is the deepest node that has both of them as descendants (a node may be a descendant of itself). Input format Input is [root, p, q] , e.g. [[6,2,8,0,4,7,9,null,null,3,5],2,8] . root is a level-order array with null for missing children; p and q are node values . TreeNode is predefined; return the value of the LCA node.

Loading workspace…