Lowest Common Ancestor of a BST
Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.
Lowest Common Ancestor of a BST

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

Example 1:
Input: {"root":[6,2,8,0,4,7,9,null,null,3,5],"p":2,"q":8}
Output: 6
Input
arr ={"root":[6,2,8,0,4,7,9,null,null,3,5],"p":2,"q":8}

Start at root

6

2

8

0

4

7

9

3

5

Variables
No variables to display
DepthFunction Call
Stack empty
0/4