Lowest Common Ancestor in an N-ary Tree

Given a rooted N-ary tree with root node 0, and two distinct nodes p and q, return their Lowest Common Ancestor (LCA).

The LCA is the deepest node that has both p and q as descendants. A no...

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: