Safest Mouse Path Away from a Cat
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Google OA reported in September 2026 hides a trap inside a friendly-looking grid problem. A mouse, a cat, water cells, and a path where only the worst cell counts. It's a maximin path problem, and the graph pattern is the whole game. If you treat it as plain shortest path, you'll pass the first example and bomb the hidden tests. Distance here is Manhattan, not walking distance, so water doesn't change the cat's reach. StealthCoder sits invisibly on your screen as a safety net if you blank on the live OA, but the approach below is short enough to carry in your head.
The problem
A square grid contains land cells marked 0 and impassable water cells marked 1. A mouse starts at start, wants to reach target, and a cat is located at cat. All three coordinates are land cells. The mouse may move one cell horizontally or vertically through land. The safety of a path is the minimum Manhattan distance from any cell on that path to the cat. Return the maximum possible safety among all mouse paths from start to target, or -1 when no path exists. Function maximumMouseSafety(grid: int[][], start: int[], target: int[], cat: int[]) → int Examples Example 1 grid = [[0,0,0],[0,0,0],[0,0,0]] start = [0,0] target = [2,2] cat = [0,2] return = 2 Following the left and bottom edges keeps every visited cell at Manhattan distance at least 2 from the cat. Example 2 grid = [[0,1,0],[0,1,0],[0,0,0]] start = [0,0] target = [0,2] cat = [1,2] return = 0 The water wall forces every route through the cat cell before reaching the target, so the minimum distance is 0. Example 3 grid = [[0,1],[1,0]] start = [0,0] target = [1,1] cat = [0,0] return = -1 Water separates the two land cells. Constraints 1 <= grid.length == grid[i].length <= 500. Every grid value is 0 or 1. start, target, and cat each contain two in-range coordinates on land.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: safety of a path is its minimum cell value, so you want the path that maximizes that minimum. Since the distance is Manhattan, compute it directly per cell as |r - cr| + |c - cc|. No BFS needed for the cat. Then pick one of two routes. Binary search a threshold d, and BFS from start using only land cells with distance >= d, checking if target is reachable. Or run a max-heap Dijkstra where each cell's value is min(parent value, cell distance). The answer is the value at target. The edge case that breaks naive solutions: start itself can be at distance 0, or the cat can sit on the only route, so the answer is capped by the start cell's distance and the target's distance. Return -1 only when water disconnects start from target, not when the answer is 0. Example 2 returns 0, Example 3 returns -1. Mixing those up is the classic miss. Grids reach 500 by 500, so avoid anything worse than roughly n squared times log.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Safest Mouse Path Away from a Cat cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as find the safest path in a grid. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Safest Mouse Path Away from a Cat FAQ
What's the trick in the Google mouse and cat grid problem?+
Safety is the minimum Manhattan distance along the path, so you maximize a minimum. Use binary search on the threshold with a BFS, or a max-heap Dijkstra that carries min(parent, cell distance). Both fit a 500 by 500 grid comfortably.
Do I need a BFS from the cat to get distances?+
No. The distance is Manhattan, so compute |r - cr| + |c - cc| for each cell directly. Water doesn't block it. A BFS from the cat would give walking distance, which is the wrong metric and fails the examples.
When do I return 0 versus -1?+
Return -1 only when water makes the target unreachable from start at all. Return 0 when a path exists but every route must touch the cat cell or end up at distance 0. Example 2 is 0, Example 3 is -1.
Is this maximin path pattern still asked?+
Yes. Maximize-the-minimum path problems show up regularly in graph rounds, including this Google OA reported in September 2026. Recognize the shape: a path score equal to its worst cell, solved by binary search plus BFS or a priority queue.
How do I prepare for this in 48 hours?+
Write the binary search plus BFS version once from scratch, then the heap version. Test with a start cell right next to the cat, a cat on a corridor, and a fully walled-off target. Those three cases cover the usual failures.