✅[Java] Solution using BFS✅
Simply apply BFS on Matrix code as gived below:\n\nclass Solution {\n    public int nearestExit(char[][] maze, int[] entrance) {\n        int r = maze.length, c
Simply apply BFS on Matrix code as gived below:\n```\nclass Solution {\n    public int nearestExit(char[][] maze, int[] entrance) {\n        int r = maze.length, c = maze[0].length;\n        int[][] directions = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n        \n        int sr = entrance[0], sc = entrance[1];\n        maze[sr][sc] = \'+\';\n        \n        // Start BFS from the entrance, and use a queue `queue` to store all \n        // the cells to be visited.\n        Queue<int[]> queue = new LinkedList<>();\n        queue.offer(new int[]{sr, sc, 0});\n        \n        while (!queue.isEmpty()) {\n            int[] currState = queue.poll();\n            int currRow = currState[0], currCol = currState[1], currDistance = currState[2];\n\n            for (int[] dir : directions) {\n                int nextRow = currRow + dir[0], nextCol = currCol + dir[1];\n\n                // If there exists an unvisited empty neighbor:\n                if (0 <= nextRow && nextRow < r && 0 <= nextCol && nextCol < c\n                   && maze[nextRow][nextCol] == \'.\') {\n                    \n                    // If this empty cell is an exit, return distance + 1.\n                    if (nextRow == 0 || nextRow == r - 1 || nextCol == 0 || nextCol == c - 1)\n                        return currDistance + 1;\n                    \n                    // Otherwise, add this cell to \'queue\' and mark it as visited.\n                    maze[nextRow][nextCol] = \'+\';\n                    queue.offer(new int[]{nextRow, nextCol, currDistance + 1});\n                }  \n            }\n        }\n\n        return -1;\n    }\n}\n```\nUpvote if you like :D
['Breadth-First Search', 'Graph', 'Queue', 'Java']