Algorithm · Bloomberg · Medium
You are given an N-ary tree rooted at node 0, together with two different nodes p and q. Find and output their Lowest Common Ancestor (LCA). The LCA of p and q is the node of greatest depth that has both of them in its subtree. Every node is treated as being its own descendant, so if one of the two nodes lies in the other's subtree, the upper one is the answer. The input is split into three lines: Line one holds n, the total number of nodes. Nodes carry IDs 0 through n - 1,…