← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE interview with a graph traversal problem that had a couple of follow-ups layered on top. Pretty standard BFS territory but the extensions pushed into weighted graph thinking, which I wasn't fully prepared for.

Questions Asked (2)

Q1

Given an unweighted graph, a start node, an end node, and a set of blocked nodes that cannot be visited, find the length of the shortest path from start to end.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

BFS was the obvious move and I got there fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., graph size, whether blocked nodes include start/end) and then propose BFS as the optimal solution for unweighted graphs. Explain how to treat blocked nodes as unvisitable and walk through the algorithm step-by-step, emphasizing time and space complexity.

Pro tip: Mention that BFS is optimal for unweighted graphs because it explores nodes in order of distance, and proactively discuss edge cases like start or end being blocked, disconnected graphs, and large inputs to show thoroughness.

1. Clarify the problem

Ask clarifying questions about graph representation, whether blocked nodes include start/end, and expected input size to ensure correct assumptions.

2. Choose the algorithm

Select BFS because it finds the shortest path in unweighted graphs by exploring level by level, and explain why DFS or Dijkstra would be suboptimal.

3. Handle blocked nodes

Treat blocked nodes as unvisitable: skip them during traversal and check if start or end is blocked, returning -1 immediately if so.

4. Implement BFS

Use a queue to track nodes and distances, a visited set to avoid cycles, and process neighbors while skipping blocked nodes until the end is reached.

5. Analyze complexity and edge cases

State O(V+E) time and O(V) space complexity, and discuss edge cases like disconnected graphs, start equals end, and large graphs.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Time complexity O(V+E) and space complexity O(V)
  • Blocked nodes are treated as unvisitable; check start/end blocked
  • Use a queue and visited set to avoid cycles and redundant work
  • Edge cases: disconnected graph, start equals end, no path exists
  • Alternative algorithms (DFS, Dijkstra) and why they are less suitable

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

Q2

If the blocked nodes can now be traversed but add extra cost, how would you find the shortest path?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This pivot to weighted traversal is where things got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a weighted graph where blocked nodes have an additional traversal cost, then apply Dijkstra's algorithm to find the shortest path. Discuss how to incorporate the extra cost into edge weights and consider any constraints or optimizations.

Pro tip: Mention that if the extra cost is uniform, you can still use Dijkstra but with modified weights; if it's non-uniform, ensure the graph remains non-negative for Dijkstra. Also, consider if the extra cost applies per node or per edge, and clarify with the interviewer.

1. Clarify the problem

Ask clarifying questions: Is the extra cost per blocked node or per edge entering a blocked node? Is it a fixed cost or variable? Are there multiple blocked nodes with different costs?

2. Model the graph

Represent the grid as a graph where each cell is a node. Assign edge weights: normal moves cost 1 (or given cost), and moves into blocked nodes cost 1 + extra_cost (or the specified extra cost).

3. Choose the algorithm

Since all edge weights are non-negative, Dijkstra's algorithm is suitable. If the graph is unweighted except for the extra cost, consider 0-1 BFS if extra cost is 1, but Dijkstra is general.

4. Implement and optimize

Implement Dijkstra with a priority queue. Discuss potential optimizations like A* with a heuristic, or bidirectional search if applicable. Mention time complexity O(E log V).

5. Discuss trade-offs

Compare with alternative approaches like BFS with state (tracking cost) or dynamic programming. Highlight that Dijkstra is optimal for non-negative weights but may be overkill if extra cost is uniform and small.

Key Points to Mention

  • Dijkstra's algorithm for weighted graphs with non-negative weights
  • Modeling blocked nodes with additional cost as edge weights
  • Time and space complexity: O(E log V) with binary heap
  • Potential use of A* with admissible heuristic for faster search
  • Handling multiple blocked nodes with varying costs
  • Clarifying whether extra cost is per node or per edge

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