← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Google SWE interview with a graph/shortest path problem. Pretty standard Dijkstra territory but the input parsing added some friction I wasn't expecting.

Questions Asked (1)

Q1

Given an undirected weighted graph provided as a formatted input string (e.g. 'node1 node2 weight; ...'), compute the shortest path distances from a given start node to all other nodes.

Algorithms & Data Structures
Author's notes

Jumped straight to Dijkstra which was the right call, but I fumbled the input parsing longer than I should have.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints (e.g., non-negative weights, graph size) and choose Dijkstra's algorithm with a min-heap for efficiency. Then, outline the parsing of the input string, construction of the adjacency list, and execution of the algorithm to compute distances. Finally, discuss handling edge cases and complexity.

Pro tip: Mention that you would use a priority queue and a visited set to avoid redundant processing, and note that if negative weights were allowed, you'd switch to Bellman-Ford. This shows awareness of algorithm trade-offs.

1. Clarify constraints and assumptions

Ask about graph size, weight ranges (negative?), and whether the graph is connected. Confirm the input format and expected output.

2. Parse input and build graph

Split the input string by semicolons and spaces to extract edges, then build an adjacency list (or matrix) for efficient traversal.

3. Choose and explain algorithm

Select Dijkstra's algorithm for non-negative weights, justifying its O((V+E) log V) time with a binary heap. If negative weights, mention Bellman-Ford.

4. Implement algorithm with data structures

Use a min-heap for unvisited nodes, a distance array initialized to infinity, and update distances via edge relaxation. Track visited nodes to avoid reprocessing.

5. Analyze complexity and edge cases

Discuss time/space complexity, handle disconnected nodes (distance remains infinity), and consider early termination if only a target node is needed.

Key Points to Mention

  • Dijkstra's algorithm with a priority queue for efficiency
  • Adjacency list representation for sparse graphs
  • Edge relaxation and distance updates
  • Time complexity O((V+E) log V) and space O(V+E)
  • Handling disconnected nodes and unreachable distances
  • Alternative algorithms (Bellman-Ford) for negative weights

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