← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE coding round, a follow-up to a grid shortest-path problem with a twist that honestly blindsided me a bit. The base problem felt manageable but the added constraint pushed me into territory I wasn't fully prepared for.

Questions Asked (1)

Q1

Given an N×N grid with land and water cells, a start cell S, an end cell T, and one cell containing a cat, find a path from S to T (moving only on land, 4 directions) that maximizes the minimum Manhattan distance between any cell along the path and the cat's cell.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I got the base BFS part fine but then just stared at the cat constraint for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Reframe the problem as finding the maximum bottleneck path, where the bottleneck is the minimum Manhattan distance to the cat along the path. Use binary search on the distance threshold and check connectivity with BFS/DFS, or use a max-heap variant of Dijkstra to directly compute the optimal path.

Pro tip: Mention that you can precompute the distance from every cell to the cat using multi-source BFS (treating the cat as the only source) to avoid recalculating Manhattan distances on the fly, which improves efficiency and simplifies the code.

1. Clarify and Restate

Confirm the problem details: grid size, movement allowed, obstacles, and that the cat's cell is impassable. Restate the goal: maximize the minimum Manhattan distance to the cat along a path from S to T.

2. Model as Bottleneck Path

Recognize that the objective is to maximize the minimum value along the path, which is a classic bottleneck path problem. The value of each cell is its Manhattan distance to the cat.

3. Choose Algorithm

Decide between binary search + BFS/DFS or a max-heap Dijkstra variant. Discuss trade-offs: binary search is simpler but may be slower; Dijkstra is more efficient but requires careful implementation.

4. Precompute Distances

Precompute the Manhattan distance from each cell to the cat, or use multi-source BFS if obstacles affect distance. This step ensures quick access to cell values during the main algorithm.

5. Implement and Test

Implement the chosen algorithm, handle edge cases (e.g., no path, cat blocking), and test with small examples. Analyze time and space complexity.

Key Points to Mention

  • Bottleneck path problem and its relation to maximum spanning tree or Dijkstra
  • Binary search on the answer with connectivity check using BFS/DFS
  • Max-heap Dijkstra to directly compute the path with maximum minimum distance
  • Precomputing Manhattan distances to the cat for efficiency
  • Time and space complexity analysis (e.g., O(N^2 log N) for binary search, O(N^2 log N) for Dijkstra)
  • Handling edge cases: no path exists, cat on start or end, obstacles

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