JS Graph BFS w/ Intuitive Comments
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {character[][]} maze\n * @param {number[]} entrance\n * @return {number}\n */\nvar nearestExit = function(maze, entrance) {\n    //helper function to check if a cell is valid\n    let isValid = (row, col) => {\n        return row >= 0 && col >= 0 && row < maze.length && col < maze[0].length && maze[row][col] !== \'+\' \n    }\n    //helper function to determine when we are at an exit\n    let isExit = (row, col) => {\n  return (row === 0 || col === 0 || row === maze.length - 1 || col === maze[0].length - 1) && maze[row][col] === \'.\' \n}\n    //initializing an array to store seen nodes\n    let seen = []\n    for (let i = 0; i < maze.length; i++) {\n        seen.push(new Array(maze[0].length).fill(false))\n    }\n    //marking the entrance as seen\n    seen[entrance[0]][entrance[1]] = true\n    //initializing our entrance node in the queue\n    let queue = [entrance]\n    let dir = [[0,1], [1, 0], [-1, 0], [0, -1]]\n    let steps = 0\n\n    while (queue.length) {\n        let nextQueue = []\n        //because our entrance is not an exit, we have to take a step\n        steps++\n        //for every node in our queue\n        for (let i = 0; i < queue.length; i++) {\n            //get its row and column\n            let [row, col] = queue[i]\n            //iterate over the directions of every potential neighbor to check them\n            for (const [dx, dy] of dir) {\n                let nextRow = row + dx, nextCol = col + dy\n                //if a node is valid and we have not seen it, then we: \n                if (isValid(nextRow, nextCol) && !seen[nextRow][nextCol]) {\n                    //see if its an exit -- if it is, return steps\n                    if (isExit(nextRow, nextCol)){ \n                        return steps\n                    } else {\n                    //otherwise we mark it as seen and push it into the queue so we can check its neighbors\n                    seen[nextRow][nextCol] = true\n                    nextQueue.push([nextRow, nextCol])\n                    }\n                }\n            }\n\n        }\n        //reup our queue\n        queue = nextQueue\n    }\n    return -1\n};\n```
['JavaScript']