Ezvor

1778. Shortest Path in a Hidden Grid

MediumArray Preparing judge… LeetCode
ArrayDepth-First SearchBreadth-First SearchMatrixInteractive

Hints

Hint 1
The grid is at a maximum 500 x 500, so it is clever to assume that the robot's initial cell is grid[501][501]
Hint 2
Run a DFS from the robot's position to make sure that you can reach the target, otherwise you should return -1.
Hint 3
Now that you are sure you can reach the target, run BFS to find the shortest path.