Check Whether Two Data Centers Are Connected by Any Link

Last updated: November 29, 2026

Quick Overview

Given n data centers labeled 0 to n-1 and a list of bidirectional network links, decide whether there is any path from a source data center to a destination data center.

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

0

0

0 solved


Given n data centers labeled 0 to n-1 and a list of bidirectional network links, decide whether there is any path from a source data center to a destination data center.

A basic graph reachability question dressed in Google's global network, where a planner wants to know if two sites can still talk after some links are taken down. The interviewer looks for building an adjacency list, choosing BFS or DFS, and stopping early once the target is found.

What the Interviewer Expects
  • Build an adjacency list from the edge list
  • Use a visited set to avoid revisiting nodes on cycles
  • Exit early when the destination is reached
  • Handle source equal to destination
  • Mention union-find as an alternative for many queries
Key Topics to Cover
graph reachability
BFS
adjacency list
union-find
early exit
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
  • How would you answer one million reachability queries on a static graph?
  • What changes if links can be added over time?
  • What if links are removed over time?
  • How would you return the actual path?
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, edges as pairs (u, v), source, destination.
  • Links are undirected; there may be cycles and isolated nodes.
  • Return True if a path exists.
  • Single query for now; follow-ups m...
High-Level Design

Build an adjacency list, then BFS from source, marking nodes visited when they are pushed. If we ever push destination, answer True. If the queue empties, the destination lives in another compon...


Submit Your Answer
Markdown supported