Avoiding the Obstacles (IMC Sydney 🦪)
In this game, a player begins on a two-dimensional grid of size n × m. One cell of the grid is marked as the end and the player wants to reach this cell by moving up, down, left or right. However, some cells are occupied by obstacles. The goal of the player is to reach the end cell using a path that maximizes the minimum distance from any obstacle along that path.
The distance between any two points on the grid with coordinates (x1, y1) and (x2, y2) is calculated as |x1 - x2| + |y1 - y2|, where |a| is the absolute value of integer a.
Notes:
Complete the function findBestPath in the editor below.
findBestPath has the following parameters:
int n: the number of rows in the gridint m: the number of columns in the gridint startRow: the row index of the starting positionint startColumn: the column index of the starting positionint endRow: the row index of the ending positionint endColumn: the column index of the ending positionint[] obstacleRow: the row index of the ith obstacleint[] obstacleColumn: the column index of the ith obstacle
Returns
int: the largest possible minimum distance from an obstacle in any path from the starting point to the ending point
1Example 1

(r, c) where r is the index of the row and c is the index of the column. Thus, the coordinates of any of the nearest obstacles is in 'Obstacle'.
Coordinates of any of the nearest obstacles thus, the obstacles in the above example are located at (0, 3) and (1,2).
Coordinates of any of the nearest obstacles is in 'Obstacle'.
* The blocked cell (1, 2) is also 3 units distant.
Return 2, the closest distance to any obstacle along the path.Constraints
Limits and guarantees your solution can rely on.
2 ≤ n, m ≤ 2000 ≤ startRow, endRow < n0 ≤ startColumn, endColumn < m0 ≤ number of obstacles = n * m - 20 ≤ obstacleRow[i] < n0 ≤ obstacleColumn[i] < m