Maximum-Clearance Path From a Point
Updated
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 shortest straight-line (Euclidean) distance from a 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.
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
- Swim in Rising WaterUiPath · PHONE SCREEN
- Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Sliding PuzzleNVIDIA · PHONE SCREENNVIDIA interview questions
- Trapping Rain Water IIBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Count Connected IslandsUber · PHONE SCREENUber interview questions
- Shortest Path with Directional Move CostsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions