← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round with a graph problem that looks straightforward until you realize there's a twist on what 'shortest total path' actually means when two nodes are both trying to reach the same destination.

Questions Asked (1)

Q1

Given an undirected graph with two nodes A and B, both need to reach node D. They can travel independently or meet at some intermediate node and continue together. Find the minimum combined path length for both to reach D.

Algorithms & Data Structures
Author's notes

The example they gave was small enough that I almost just hardcoded a BFS and called it a day.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as finding a meeting node M that minimizes dist(A, M) + dist(B, M) + 2 * dist(M, D), where dist is the shortest path distance. Precompute shortest paths from A, B, and D using BFS (for unweighted) or Dijkstra (for weighted), then iterate over all nodes to find the minimum. Also consider the case where they never meet (M = D) as a special case.

Pro tip: Clarify with the interviewer whether the graph is weighted or unweighted, as this determines the algorithm choice. Mentioning edge cases like disconnected graphs or when A or B is already at D shows thoroughness.

1. Clarify problem constraints

Ask about graph size, weighted vs unweighted edges, and whether nodes can be revisited. Confirm that the goal is to minimize the sum of distances traveled by both agents.

2. Define meeting point formulation

Let M be the node where they meet (M could be D if they never meet). The total distance is dist(A, M) + dist(B, M) + 2 * dist(M, D). Explain why the factor 2 appears: both travel from M to D together.

3. Precompute shortest paths

Run BFS from A, B, and D (or Dijkstra if weighted) to get distances from each to all nodes. This takes O(V+E) per BFS for unweighted graphs.

4. Iterate to find optimal meeting point

For each node M, compute the total distance using the precomputed distances, and track the minimum. Also consider M = D as the no-meet case.

5. Analyze complexity and edge cases

State time complexity O(V+E) for unweighted (or O((V+E) log V) for weighted) and space O(V). Discuss handling disconnected graphs (return infinity) and nodes already at D.

Key Points to Mention

  • Shortest path algorithms: BFS for unweighted, Dijkstra for weighted
  • Meeting point formulation: dist(A, M) + dist(B, M) + 2 * dist(M, D)
  • Precomputation of distances from A, B, and D
  • Iterating over all nodes to find minimum total distance
  • Time and space complexity analysis
  • Edge cases: disconnected graph, A or B already at D, multiple optimal meeting points

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