Skip to main content
mediumBlind 75

Lowest Common Ancestor of a Binary Search Tree

Return the value of the lowest common ancestor of nodes p and q Example: [6,2,8,0,4,7,9,null,null,3,5], p=2, q=8 => 6

This one is a traversal problem: the hard part is modeling the state you visit. Interviewers love it because it reveals your traversal modeling and your edge-case discipline. The trap is revisiting states or missing a base case; your visited/queue logic needs to be tight.

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.

1Lowest Common Ancestor of a BSTmedium

Prep guides that list this problem

Our company tags come from public interview write-ups. None of these is a confirmed question.

Get a note when something new lands

New company guides, new problems and big changes to Coco. Rare, and you can leave any time. By joining you agree to get these emails.