← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE interview with a grid-based pathfinding problem that had a neat twist on the usual shortest path setup. The problem was harder than it looked on the surface.

Questions Asked (1)

Q1

Given a grid containing a rat, a piece of bread, a cat, and some obstacles, find a path from the rat to the bread that maximizes the minimum distance from the cat at any point along the path.

Algorithms & Data Structures
Author's notes

My first instinct was BFS and I started coding before fully thinking through what 'maximize the minimum distance' actually means.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each cell is a node, and the 'safety' of a path is the minimum distance to the cat along that path. Use binary search on the safety value combined with BFS/DFS to check if a path exists using only cells with distance to cat >= safety, or use a max-min path algorithm like Dijkstra with a modified priority (maximizing the minimum).

Pro tip: Clarify assumptions upfront: whether the cat is stationary, whether diagonal moves are allowed, and whether the cat can move. This shows you think about edge cases and problem constraints before diving into the algorithm.

1. Clarify problem constraints

Ask about grid size, movement rules (4-directional vs 8-directional), whether the cat is stationary, and if the cat can move. Confirm that the goal is to maximize the minimum distance to the cat along the path.

2. Precompute distances to cat

Run BFS from the cat's position to compute the shortest distance from every cell to the cat. This gives a distance map that will be used to evaluate path safety.

3. Choose algorithm for max-min path

Use binary search on the safety threshold combined with BFS/DFS to check connectivity, or use a modified Dijkstra that maximizes the minimum distance. Explain the trade-offs between approaches.

4. Implement and handle edge cases

Code the chosen algorithm, ensuring to handle cases where no path exists, the rat or bread is unreachable, or the cat blocks all paths. Consider obstacles and boundaries.

5. Analyze complexity and optimize

Discuss time and space complexity. For binary search + BFS, it's O(log(maxDist) * (R*C)). For modified Dijkstra, it's O(R*C log(R*C)). Mention potential optimizations like early termination.

Key Points to Mention

  • Modeling the grid as a graph with cells as nodes and edges between adjacent cells.
  • Precomputing distances to the cat using BFS to define safety of each cell.
  • Binary search on the answer (safety threshold) with a feasibility check via BFS/DFS.
  • Alternative approach: modified Dijkstra that maximizes the minimum distance (max-min path).
  • Time and space complexity analysis for each approach.
  • Handling edge cases: no path, cat adjacent to rat or bread, obstacles blocking all paths.

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