Maximum-Clearance Path From a Point
Problem statement
You are given a rectangular binary grid, two open cells start and target, and a reference cell reference. A cell containing 1 is open and a cell containing 0 is a wall.
A path may move one cell up, down, left, or right through open cells and may not repeat a cell. Its clearance is the minimum Euclidean distance from any cell on the path to reference.
Return the maximum clearance among all paths from start to target. An answer within 10^-6 is accepted. A valid path is guaranteed to exist; reference may itself be open or blocked.
Function
maximumClearancePath(grid: int[][], start: int[], target: int[], reference: int[]) → doubleExamples
Example 1
grid = [[1,1,1],[1,1,1],[1,1,1]]start = [0,0]target = [0,2]reference = [2,1]return = 2.0The top-row path stays at least distance 2 from the reference. Any detour lower in the grid comes closer.
Example 2
grid = [[1,1,1],[1,1,1],[1,1,1]]start = [0,0]target = [2,2]reference = [1,1]return = 1.0A boundary path avoids the reference itself but must use a cell one unit away.
Example 3
grid = [[1,0,1],[1,1,1],[0,0,1]]start = [0,0]target = [2,2]reference = [2,0]return = 1.0The walls force the path through [1,0], whose distance from the reference is 1.
Constraints
1 <= rows,cols <= 500.- Every grid cell is
0or1. start,target, andreferenceare valid zero-based coordinates.startandtargetare open and connected by at least one open-cell path.