Lowest Common Ancestor of a Binary Tree

Given the root of a binary tree and the values of two distinct nodes p and q in the tree, return the value of their lowest common ancestor (LCA).

The LCA is the lowest node that has both p and ...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: