Find the Extra Reporting Line That Broke a Rooted Org Chart

Last updated: November 29, 2026

Quick Overview

An org chart of n employees was a rooted tree with directed edges manager to report, then one extra directed edge was added. Given the edges in order, return the edge to remove so the result is a rooted tree again; if several work, return the one appearing last.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


An org chart of n employees was a rooted tree with directed edges manager to report, then one extra directed edge was added. Given the edges in order, return the edge to remove so the result is a rooted tree again; if several work, return the one appearing last.

The directed version of the redundant link problem is a well-known Google onsite question because the case analysis is easy to get wrong. The interviewer checks that you identify both failure types (a node with two parents and a cycle), handle the case where both happen at once, and justify which edge to drop.

What the Interviewer Expects
  • Detects whether some employee has two managers
  • Records both candidate edges in that case
  • Runs union-find while skipping the later candidate
  • Returns the earlier candidate if a cycle remains, else the later one
  • Falls back to the cycle-closing edge when no node has two parents
Key Topics to Cover
Union-Find
Directed Graphs
Case Analysis
Trees
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
  • Prove that the case analysis covers every possible input.
  • What if more than one extra edge was added?
  • How would you report the full cycle to the person editing the chart?
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: list of (u, v) edges meaning u manages v, over employees 1..n, with n edges in total.
  • Exactly one edge is extra.
  • Output: the edge to remove, preferring the last valid one in input o...
High-Level Design

Three cases. First, scan for an employee with two incoming edges; if found, call the earlier edge cand1 and the later cand2. Then run union-find over all edges except cand2. If no cycle appears,...


Submit Your Answer
Markdown supported