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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
union find
directed graph
rooted tree
case analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: edges of length n, each [parent, child], nodes 1..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:

  1. Two parents, no cycle. Some child v has parents via edges cand1 (earlier) and cand2 (later). Removing cand2 works and i...

Submit Your Answer
Markdown supported