← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round, one graph problem the whole session. Pretty standard Dijkstra territory but the edge case around unreachable nodes is where things get interesting.

Questions Asked (1)

Q1

Given a weighted directed graph and a starting node, find the minimum time for a signal to reach every other node. Return the maximum of all shortest path times, or -1 if any node can't be reached.

Algorithms & Data Structures
Author's notes

Classic Dijkstra setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a classic single-source shortest path problem on a weighted directed graph with non-negative weights, so Dijkstra's algorithm is the optimal choice. Run Dijkstra from the starting node to compute the shortest time to each node, then return the maximum of these times, or -1 if any node is unreachable.

Pro tip: Mention that if edge weights can be negative, Dijkstra fails and you'd need Bellman-Ford, but since time is non-negative, Dijkstra is safe and more efficient. Also, clarify that the graph may not be connected, so you must check for unreachable nodes.

1. Clarify assumptions and edge cases

Confirm that edge weights are non-negative (time delays) and that the graph may have unreachable nodes. Discuss what to return if the start node is isolated or if there are zero nodes.

2. Choose the algorithm

Select Dijkstra's algorithm for its O((V+E) log V) time complexity with a priority queue, which is optimal for non-negative weights. Mention alternatives like Bellman-Ford if negative weights were allowed.

3. Implement Dijkstra

Initialize distances to infinity, set start node distance to 0, and use a min-heap to repeatedly extract the node with the smallest tentative distance and relax its outgoing edges.

4. Compute the result

After Dijkstra completes, find the maximum distance among all nodes. If any node still has distance infinity, return -1; otherwise, return that maximum.

5. Analyze complexity and test

State the time complexity O((V+E) log V) and space complexity O(V+E). Walk through a small example to verify correctness, including a case with an unreachable node.

Key Points to Mention

  • Dijkstra's algorithm is optimal for non-negative edge weights.
  • Use a priority queue (min-heap) for efficiency.
  • Track visited nodes to avoid reprocessing.
  • Check for unreachable nodes by verifying if any distance remains infinity.
  • Return the maximum of the shortest path distances.
  • Time complexity: O((V+E) log V) with a binary heap; space complexity: O(V+E).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.