Back to problems

Validate a Forest from (parent, child) Edges

Algorithm · Waymo · Medium

Requirements Input: a graph represented by a list of directed (parent, child) edge pairs, passed to a function such as is_valid_forest(edges). Output: determine whether those edges describe a valid forest, meaning one or more separate trees. During the interview, the candidate should come up with their own test scenarios. Notes Forest definition. A node may have no more than one parent, cycles are forbidden, and the graph must consist of one or more independent trees.…

Checking your access…