FastPrepRat's Safest Path
Problems/Rat's Safest Path

Rat's Safest Path

Google logoGoogle● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported exercise gives the grid, the endpoints, a cat that stays still, the movement rule, and a goal of maximizing the smallest distance. We defined what happens when an endpoint is blocked, and the function signature. Our version is about 97% the same as the reported question.

In a square grid, 1 is open land and 0 is blocked water. Move from source to target through open cells in four directions. A stationary cat occupies cat.

The safety of a path is the minimum Manhattan distance from the cat among all cells on the path. Return the maximum possible safety, or -1 when no path exists.

Function

maximumPathSafety(grid: int[][], source: int[], target: int[], cat: int[]) → int

Examples

Example 1

grid = [[1,1,1],[1,0,1],[1,1,1]]source = [0,0]target = [2,2]cat = [0,2]return = 2
grid
012011111012111

The route around the left and bottom edges stays at least two cells from the cat.

Example 2

grid = [[1,1,1],[1,1,1],[1,1,1]]source = [0,0]target = [2,0]cat = [0,2]return = 2
grid
012011111112111

The left column keeps distance at least two.

Constraints

  • 1 <= grid.length == grid[i].length <= 300.
  • Coordinates are valid; source and target may be blocked.

Source note: Author-written prompt excerpt retained for source fidelity.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Path with Directional Move CostsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Minimum-Cost Path Through a Weighted GridVisa · OAVisa interview questions
  • Cookie Monster Minimum Arrival TimeIntuit · OAIntuit interview questions
  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Topological OrderingApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Network Layer Execution OrderNVIDIA · PHONE SCREENNVIDIA interview questions
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int maximumPathSafety(int[][] grid, int[] source, int[] target, int[] cat) {
        // Write your code here.
    }
}
Checking account…