Find the Redundant Cable That Creates a Loop in a Rack Network

Last updated: November 29, 2026

Quick Overview

A data center rack network of n racks was a tree until one extra cable was added, creating exactly one loop. Given the cables in installation order, return the cable that can be removed to restore a tree, choosing the one installed last if several qualify.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A data center rack network of n racks was a tree until one extra cable was added, creating exactly one loop. Given the cables in installation order, return the cable that can be removed to restore a tree, choosing the one installed last if several qualify.

AWS data centers depend on loop-free topologies at certain network layers. This phone screen question checks that you know the union find cycle test: an edge whose endpoints already share a root closes a loop.

What the Interviewer Expects
  • Process cables in order with a DSU
  • Return the first cable whose endpoints are already connected
  • Explain why that cable is also the last one in the loop
  • O(n alpha(n)) time
  • Handle 1-indexed labels
Key Topics to Cover
union find
cycle detection
spanning tree
graphs
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
  • What changes if cables are directed (a rooted tree with one extra edge)?
  • How would you return every cable on the loop?
  • How would you do this with DFS instead?
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: n racks labeled 1..n and n cables, forming a tree plus one edge. Output: the cable to remove; among cables on the cycle, the one that appears last in the input....

High-Level Design

Add cables one at a time. While no cycle exists, each cable joins two different components. The first cable whose endpoints are already in the same component is the one that closes the loop.

Why it i...


Submit Your Answer
Markdown supported