← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026Remote

Summary

Google SWE coding round, one graph problem, pretty straightforward if you've done any shortest path stuff before. Felt decent about my solution but the whole thing was over faster than I expected.

Questions Asked (1)

Q1

You have a directed weighted graph of n nodes and a list of edges where each edge (u, v, w) means a signal takes w time to travel from u to v. Starting from source node k, what is the minimum time for the signal to reach every node? Return -1 if any node is unreachable.

Algorithms & Data Structures
Author's notes

Classic Dijkstra setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a single-source shortest path problem on a directed graph with non-negative weights, so Dijkstra's algorithm is optimal. Use a priority queue to efficiently extract the minimum distance node and relax its outgoing edges. After computing distances, replace any infinite distances with -1 to indicate unreachable nodes.

Pro tip: Mention that if edge weights can be negative, Dijkstra fails and Bellman-Ford is needed, but since the problem implies non-negative weights, Dijkstra is the right choice. Also, discuss the time complexity O((n + m) log n) and how it compares to Bellman-Ford's O(nm).

1. Clarify the problem and constraints

Confirm that edge weights are non-negative and that the graph is directed. Ask about the expected input format and any constraints on n and m.

2. Choose the algorithm

Select Dijkstra's algorithm because it efficiently finds shortest paths from a single source in graphs with non-negative weights. Mention that Bellman-Ford would be used if negative weights were present.

3. Implement Dijkstra with a priority queue

Initialize distances to infinity except the source (0). Use a min-heap to repeatedly extract the node with the smallest tentative distance and relax its outgoing edges.

4. Handle unreachable nodes and return result

After the algorithm completes, replace any remaining infinity distances with -1. Return the array of minimum times.

5. Analyze complexity and edge cases

State the time complexity O((n + m) log n) and space complexity O(n + m). Discuss edge cases like disconnected graph, single node, or source with no outgoing edges.

Key Points to Mention

  • Dijkstra's algorithm is optimal for non-negative weights; Bellman-Ford for negative weights.
  • Use a priority queue (min-heap) to achieve O((n + m) log n) time.
  • Initialize distances to infinity and set source distance to 0.
  • Relaxation step: if dist[u] + w < dist[v], update dist[v].
  • After algorithm, convert infinity to -1 for unreachable nodes.
  • Consider edge cases: disconnected graph, zero-weight edges, large graphs.

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