[JavaScript] Neat: bfs
js\nconst nearestExit = (maze, [y0, x0]) => {\n    maze[y0][x0] = \'@\'\n    const queue = [[y0, x0, 0]]\n    while (queue.length) {\n        const [y, x, step]
```js\nconst nearestExit = (maze, [y0, x0]) => {\n    maze[y0][x0] = \'@\'\n    const queue = [[y0, x0, 0]]\n    while (queue.length) {\n        const [y, x, step] = queue.shift()\n        for (const [dy, dx] of [[-1, 0], [0, -1], [1, 0], [0, 1]]) {\n            const ny = y + dy, nx = x + dx\n            if (!maze[ny]?.[nx]) {\n                if (step) return step\n            } else if (maze[ny][nx] === \'.\') {\n                queue.push([ny, nx, step + 1])\n                maze[ny][nx] = \'*\'\n            }\n        }\n    }\n    return -1\n}\n```\n
['JavaScript']