1931. Shortest Path in a Hidden Grid

Medium
Array
Depth-First Search
Breadth-First Search
Matrix
Interactive

Description

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.

Statistics

Acceptance
44.5%
Submissions
38,961
Accepted
17,339