Given a Binary Search Tree (BST), find the
lowest common ancestor (LCA) of two given nodes
p and q.
The lowest common ancestor is defined as the lowest node in the tree
that has both p and q as descendants
(where a node can be a descendant of itself).
null for empty)pqInput: [6,2,8,0,4,7,9,null,null,3,5] 2 8 Output: 6
Input: [6,2,8,0,4,7,9,null,null,3,5] 2 4 Output: 2
Your program must print only the value of the lowest common ancestor.
No submissions yet.
Discuss BST properties, iterative vs recursive approaches.