Lowest Common Ancestor of a Binary Tree with Existence Validation

Given the root of a binary tree and two target values p and q (node values are unique), return the lowest common ancestor (LCA) of the corresponding nodes.

Additional requirement: Return `nul...

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: