FastPrepDistances While Avoiding a Broken Node
Problems/Distances While Avoiding a Broken Node

Distances While Avoiding a Broken Node

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives a graph with cycles and asks whether you can get from start to end while one node is broken. A follow-up asks for the minimum distance from the start to every node you can reach. Here the function returns the full list of distances on a directed graph. Our version is about 91% the same as the reported question.

You are given a directed unweighted graph with vertices 0 through n-1, a start vertex, and one broken vertex that cannot be visited.

For every vertex, return the fewest edges needed to reach it from start without visiting the broken vertex. Use -1 for unreachable vertices, including the broken vertex. If start is broken, return all -1.

Cycles and duplicate edges are allowed.

Function

distancesAvoidingBroken(n: int, edges: int[][], start: int, broken: int) → int[]

Examples

Example 1

n = 5edges = [[0,1],[1,2],[0,3],[3,2],[2,4]]start = 0broken = 1return = [0,-1,2,1,3]

Vertex 2 is reached through 0→3→2 because vertex 1 is unavailable.

Example 2

n = 3edges = [[0,1],[1,2],[2,0]]start = 0broken = 2return = [0,1,-1]

The cycle is handled without revisiting vertices.

Example 3

n = 3edges = [[0,1]]start = 1broken = 1return = [-1,-1,-1]

A broken start cannot reach any vertex.

Constraints

  • 1 <= n <= 200000.
  • 0 <= edges.length <= 400000.
  • Every edge contains two valid vertex IDs.
  • start and broken are valid vertices.

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

Interview reports that mention this question

  • Google Early Career R1 Rejection: 1 Experience

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] distancesAvoidingBroken(int n, int[][] edges, int start, int broken) {
        // Write your code here.
    }
}
Checking account…