Find Maximum Distance
Learn this problemProblem statement
The city of Hackerland can be represented as a two-dimensional grid of size n x m. Each cell is either empty (a dot character .), has an obstacle (an asterisk *), an S, or an E that represent the start and end points respectively.
One can move in four directions: up, down, left, and right. The goal is to move from the starting point to the ending point such that in the path, the minimum distance from any obstacle is as large as possible. Return this minimum possible distance.
The distance between any two points on the grid with coordinates (r1, c1) and (r2, c2) is calculated as |r1 - r2| + |c1 - c2|, where |a| is the absolute value of integer a.
Notes:
Function
findMaximumDistance(grid: String[]) → int
Complete the function findMaximumDistance in the editor below.
findMaximumDistance has the following parameter:
String grid[n]: An array of strings that represent the rows of the grid.
Returns
int: the largest possible minimum distance from an obstacle in any path from the starting point to the ending point
Examples
Example 1
grid = [" S . . *", ". . * .", ". . . .", ". . . E"]return = 2
Consider the following grid of size 4*4:
S . . *
. . * .
. . . .
. . . E
The optimal path is shown in the 'Cell' column. Coordinates of any of the nearest obstacles is in 'Obstacle'.
Return 2, the closest distance to any obstacle along the path.
Constraints
2 ≤ n, m ≤ 200grid[i][j]='.'if the cell is empty.
More Wells Fargo problems
- Count Server ReplacementsOA · Seen Feb 2026
- Minimum Remaining LengthOA · Seen Feb 2026
- Compressing ArraySeen Dec 2024
- Sum of Compressed Number for All SubarraysSeen May 2024
- Allocate Wells for Fair DistributionSeen Oct 2023
- Count OperationsSeen Aug 2023
- Get SubstringSeen Aug 2023
- Find Last Affected SystemSeen May 2022