Back to problems

Find Tree Root from Edge List

Algorithm · Bloomberg · Medium

Requirements You receive pairs in the form [node, [children]] that represent a directed tree, where every child is assigned to one and only one parent. Determine the tree root: it is present as a parent and does not occur in any child list. Function signature: Follow-ups: If cycles or separate connected groups are present, identify the invalid input and report an error. When more than one node lacks a parent, the input describes a forest; return every such node. Process…

Checking your access…