Skip to main content
mediumGrind 75

Lowest Common Ancestor of a Binary Tree

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

I return the node itself when I find it, and null when I do not. The first node that hears back from both sides is the answer.

BFS / DFSTrees

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. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Lowest Common Ancestor of a Binary Treemedium
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.