Back to problems

Identify the Extra Directed Edge

Algorithm · Microsoft · Hard

You are given an array edges in which each entry is a directed edge [parent, child]. The graph has n nodes labeled from 1 to n, and n == edges.length. These edges were produced by taking a valid rooted tree and adding exactly one extra directed edge. A directed rooted tree must satisfy all of the following: There is exactly one root: a node with no incoming edge. Every other node has exactly one incoming edge. Every node can be reached by following directed edges from the…

Checking your access…