Back to problems

Solve Three Coding Interview Problems

Algorithm · Meta · Hard

Task 1 An n-node rooted N-ary tree is described by the array children, where children[i] is the list of child node IDs of node i. The root is node 0, and node IDs are the same as the node values. You are given children and two node IDs p and q that are guaranteed to appear in the tree. Return the node ID of their lowest common ancestor (LCA). The LCA is the deepest node that has both p and q as descendants; a node is treated as a descendant of itself. Example 1: Explanation:…

Checking your access…