Beginner Friendly Standard BFS [8ms]
class Solution {\n\n    public int nearestExit(char[][] maze, int[] entrance) {\n        int rows = maze.length, cols = maze[0].length;\n        \n        Queue
class Solution {\n\n    public int nearestExit(char[][] maze, int[] entrance) {\n        int rows = maze.length, cols = maze[0].length;\n        \n        Queue<int[]> queue = new LinkedList<>();\n        boolean[][] visited = new boolean[rows][cols];\n        \n        int[][] dirs = {{0,1},{0,-1},{1,0},{-1,0}}; //directions array\n        int x, y;\n        int steps = 0; //intializing steps \n        \n        queue.offer(entrance); //adding the entracne coordinates to the bfs queue\n        visited[entrance[0]][entrance[1]] = true; //marking the entrance as visited\n        \n        while (!queue.isEmpty()) {\n            int queueSize = queue.size(); \n            steps++; //incrementing the steps as we proceed with bfs\n            \n            for (int i=0;i<queueSize;i++) {\n                int[] curr = queue.poll(); //polling from the queue\n                \n                for (int[] dir: dirs) {  //perfoming standard bfs\n                    x = dir[0]+curr[0];                    \n                    y = dir[1]+curr[1];\n                    \n                    //base condition\n                    if (x<0||x>=rows||y<0||y>=cols) continue;\n                    \n                    //skip if we encounter a wall or if the cell is already visited\n                    if (visited[x][y] || maze[x][y] == \'+\') continue;\n                    \n\t\t\t\t\t// check if we have reached boundary\n                    if (x==0||x==rows-1||y==0||y==cols-1) return steps;\n                    \n                    queue.offer(new int[]{x, y}); //we found a new valid coordinate so add it to the queue\n                    visited[x][y] = true; //mark its visited as true\n                }\n            }\n        }\n        \n        return -1; //if there are no exits we return -1\n    }\n}
['Breadth-First Search']