Implement it on LeetCode. The recursive version is equally simple: text function lowestCommonAncestor(root, p, q): if p.val < root.val and q.val < root.val: return lowestCommonAncestor(root.left, p, q) if p.val > root.val and q.val > root.val: return lowestCommonAncestor(root.right, p, q) return root Note: the general binary tree version is harder. You can't use BST properties and must search both subtrees.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/trees-bst/lowest-common-ancestor-of-bst-implementation
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████████████████████████████████████