Standard Bar Graphs · Shortest Path Problems O(n^2) · O(n^2)
A warehouse robot must travel from the north-west corner to the south-east corner of a floor grid. Blocked bays are marked 1 and open bays 0, and the robot may roll in any of the eight directions — including diagonals — across open bays only. The route planner wants the shortest run measured in bays entered, or confirmation that no diagonal-capable route exists.
Input: An n x n binary matrix grid where 0 is open and 1 is blocked.
Output: Return the number of cells on the shortest clear path from (0,0) to (n-1,n-1), or -1 if no such path exists.
1 <= n <= 100grid[0][0] and grid[n-1][n-1] may need checking — the path must start and end on open cellsgrid[i][j] is 0 or 1Input: {"grid":[[0,1],[1,0]]}
Output: 2
The diagonal hop from corner to corner visits exactly two cells.
Input: {"grid":[[0,0,0],[1,1,0],[1,1,0]]}
Output: 4
The only corridor hugs the top row and the right column: four bays.