Lowest Common Ancestor in a BST

easy
Unit 5 · Trees0/3 to milestone

In a BST, the lowest common ancestor of two values p and q (both present) is the first node, walking down from the root, whose value lies between them (inclusive). Implement lca(root, p, q) returning that node's value, iteratively in O(height).

TreeNode and build are provided.

#trees#bst2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Lowest Common Ancestor in a BST · TechGradify