FastPrepMaximum Safeness of a Grid Path
Problems/Maximum Safeness of a Grid Path

Maximum Safeness of a Grid Path

Intuit logoIntuit● MediumNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says the LeetCode question was probably 2812.

The report does not restate the task. Here, that tentative reference is resolved to the standard grid path objective: maximize the minimum Manhattan distance to any thief, with four-direction moves and thief cells still traversable.

The judged core task matches the tentative reference at about 80%.

In an n by n binary grid, a 1 marks a thief and a 0 marks an empty cell. Travel from the top-left cell (0,0) to the bottom-right cell (n-1,n-1) by moving one cell up, down, left, or right. You may enter a cell containing a thief.

A cell's safety is its minimum Manhattan distance to any thief. The Manhattan distance from (r,c) to (x,y) is |r-x| + |c-y|. A path's safeness is the smallest cell safety anywhere on that path, including both endpoints.

Return the largest safeness achievable by any valid start-to-finish path. At least one thief exists, so every cell has a finite safety.

For this exercise, assume the tentative problem-number reference identifies this standard maximum-safeness task. The full practice rules above define the judged behavior.

Function

maximumSafenessFactor(grid: int[][]) → int

Examples

Example 1

grid = [[0,0,1],[0,0,0],[0,0,0]]return = 2

Take the left column and then the bottom row. Distances to the thief at (0,2) along this path are 2, 3, 4, 3, and 2. Its minimum is 2. Since the start has safety 2, no path can achieve more.

Example 2

grid = [[0,0],[0,1]]return = 0

The finish contains a thief, so every path includes a cell of safety 0. Reaching the finish is allowed, and the best safeness is 0.

Constraints

  • 1 <= grid.length <= 400.
  • Every row has exactly grid.length cells.
  • Every cell is 0 or 1, and at least one cell is 1.

More Intuit problems

  • VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
All Intuit interview questionsSee Intuit hiring insights
Saved
public int maximumSafenessFactor(int[][] grid) {
    // Write your code here
}
Checking account…