Remove the Directed Edge That Breaks a Rooted Reporting Tree
Last updated: November 29, 2026
Quick Overview
An org chart was a rooted tree with n people, where each edge [manager, report] points from a manager to a direct report. Exactly one extra directed edge was added. Return the edge that can be removed to restore a rooted tree, choosing the one that appears last in the input if several work.
Meta
November 29, 20260
0
0 solved
An org chart was a rooted tree with n people, where each edge [manager, report] points from a manager to a direct report. Exactly one extra directed edge was added. Return the edge that can be removed to restore a rooted tree, choosing the one that appears last in the input if several work.
A hard Meta onsite question that builds on the undirected redundant edge problem, framed around repairing a corrupted org chart import. The interviewer checks that you handle both failure modes: a node with two parents, and a directed cycle, including the case where both happen at once.
What the Interviewer Expects
- Detect a node with two incoming edges and record both candidates
- Run union find while skipping the second candidate
- Use cycle detection to decide which candidate to drop
- Handle the pure cycle case with no double parent
- Explain the tie-break toward the later edge
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Why is the undirected union find solution insufficient here?
- Prove the case analysis covers every possible extra edge.
- How would you handle several extra edges?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
edgesof lengthn, each[parent, child], nodes1..n. - Output: an edge whose removal leaves a rooted tree, the last such edge in input order if several qualify....
High-Level Design
Adding one edge to a rooted tree breaks it in one of three ways:
- Two parents, no cycle. Some child
vhas parents via edgescand1(earlier) andcand2(later). Removingcand2works and i...