FastPrepServer Network Distances with a Failure Radius
Problems/Server Network Distances with a Failure Radius

Server Network Distances with a Failure Radius

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes one BFS problem about servers passing messages, asked in four steps. First, the shortest hop count between two servers. Second, whether a message can still get through when some servers have failed. Third, the distances from one server to every reachable healthy server. Finally, failures that also take down every server within a given distance. It suggests two searches for the last step and lists edge cases such as a failed start and a radius of zero. A reply from the author confirms that the steps were follow-ups to one search problem.

The report gives no input format or limits. We chose these: servers are numbered 0 to n - 1 and links go both ways. One function covers all four steps by returning each reachable healthy server with its hop count, sorted by server number. The failure distance is measured in the full network and does not chain from servers it takes down. A disabled start gives an empty result. Because servers are numbered, the report's case of a server that does not exist does not apply here. The size limits are also our choice.

Our version is about 80% the same as the reported question.

A network has n servers numbered 0 to n - 1. Each connections[i] = [u, v] is a two-way link, and sending a message across one link takes one hop.

Some servers have failed, listed in failed. A failure also takes down every server whose shortest hop distance to a failed server is at most radius, measured in the full network. These servers are disabled. Servers taken down this way do not spread the failure any further.

A message from start can pass only through servers that are not disabled. Return every server the message can reach, including start itself, as pairs [server, hops], where hops is the fewest hops needed. Sort the pairs by server number. Leave out disabled servers and servers that cannot be reached. If start is disabled, return an empty array.

When failed is empty, each pair gives the shortest hop count from start to that server, and a server with no pair cannot be reached from start at all.

Function

serverDistances(n: int, connections: int[][], start: int, failed: int[], radius: int) → int[][]

Examples

Example 1

n = 6connections = [[0,1],[1,2],[2,3],[0,4],[4,3],[3,5]]start = 0failed = []radius = 0return = [[0,0],[1,1],[2,2],[3,2],[4,1],[5,3]]

No server has failed. A breadth-first search from server 0 reaches 1 and 4 in one hop, 2 and 3 in two hops (3 through 4), and 5 in three hops. Every server is listed with its hop count.

Example 2

n = 6connections = [[0,1],[1,2],[2,3],[0,4],[4,3],[3,5]]start = 0failed = [4]radius = 0return = [[0,0],[1,1],[2,2],[3,3],[5,4]]

Server 4 has failed and radius 0 disables only server 4. Messages must now go 0, 1, 2, 3, so server 3 is three hops away and server 5 is four.

Example 3

n = 7connections = [[0,1],[1,2],[2,3],[3,4],[4,5],[0,6]]start = 0failed = [3]radius = 1return = [[0,0],[1,1],[6,1]]

Server 3 fails with radius 1, so servers 2, 3 and 4 are disabled. From server 0, only servers 1 and 6 can still be reached; server 5 is cut off.

Constraints

  • 1 <= n <= 2000
  • 0 <= connections.length <= 4000
  • connections[i] = [u, v] with 0 <= u, v < n and u != v; no pair of servers is linked twice.
  • 0 <= start < n
  • 0 <= failed.length <= n; the values in failed are distinct and each is in [0, n - 1].
  • 0 <= radius <= n

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Crawl Same-Hostname URLs ConcurrentlyAnthropic · PHONE SCREENAnthropic interview questions
  • Possible BipartitionByteDance · PHONE SCREENByteDance interview questions
  • Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] serverDistances(int n, int[][] connections, int start, int[] failed, int radius) {
        // Write your code here.
    }
}
Checking account…