Skip to main content
Admissions guidance, study banks, and career tools โ€” get started on Shalyam

Lowest Common Ancestor of a Binary Tree

Medium Binary Trees

Given a binary tree (level-order form, unique values) and two values p and q that exist in the tree, print the value of their lowest common ancestor.

Constraints

2 <= number of nodes <= 10^5 All values are unique

Discussion

No discussions yet.

Rewards ยท v2.1

Join Shalyam Newsletter

Get exclusive insights with every issue: education, research and innovation news.

One email a week. Unsubscribe any time.