LeetCode 235 ·
Medium
Lowest Common Ancestor of a BST
Find the lowest common ancestor of two nodes in a BST.
Try it
Step through the core mechanic. The simulator below runs the recursion shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Recursion — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Walk from the root: if both targets are larger, go right; if both smaller, go left; otherwise this node is the split point and the LCA. The BST ordering makes it O(h).
| Aspect | Value |
|---|---|
| Pattern | Recursion |
| Recognise it by | Split point where two values diverge in a BST. |
| Time complexity | O(h) |
| Space complexity | O(1) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.