How do you find the LCA of two nodes in a BST?
PICTURE THIS: HOW TO EXPLAIN IT
Simple meaning
Walk from the root: go left if both keys are smaller, right if both are larger
WHY — BST instead of guessing?
Why interviewers care about BST:
question about BST.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1Walk from the root:
go left if both keys are smaller, right if both are larger
- 2otherwise the split node
is the LCA.
- 3Time is O(h) and
extra space is O(1) iterative.
- 4This uses the ordering
invariant and is simpler than general-tree LCA.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
Walk from the root: go left if both keys are smaller, right if both are larger otherwise the split node is the LCA.