Shortest path in a maze
Mediumgraphbfsmatrix
grid is a maze: "0" is open and "1" is a wall. You move up/down/left/right. Return the fewest cells on a path from the top-left cell to the bottom-right cell (both counted), or -1 if there's no path.
Example 1
Input: grid = ["00","10"] Output: 3
(0,0) → (0,1) → (1,1): 3 cells.
Example 2
Input: grid = ["010","010","000"] Output: 5
Example 3
Input: grid = ["01","10"] Output: -1
Constraints
- 1 ≤ rows, cols ≤ 100
- Each cell is "0" or "1"
Submit checks your solution against 9 tests, including hidden ones.
/**
* @param {string[]} grid
* @return {int}
*/
function shortestPath(grid) {
}