C++ Solution using BFS (with comments)
The main idea is to perform BFS in all 4 directions and return the number of steps as soon as you find a valid empty cell.\n\n\nclass Solution {\npublic:\n    /
The main idea is to perform BFS in all 4 directions and return the number of steps as soon as you find a valid empty cell.\n\n```\nclass Solution {\npublic:\n    //checks if the coordinates of the cell are that of an unvisited valid empty cell\n    bool isValid(int x,int y,int n,int m, vector<vector<char>>& maze,vector<vector<int>>& visited){\n        if(x>=0 && x<n && y>=0 && y< m && maze[x][y]!=\'+\' && visited[x][y]!=1){\n            return true;\n        }\n        return false;\n    }\n    \n    //checks if the cell is a valid exit point\n    bool isExit(int x,int y,int startX,int startY, vector<vector<char>>& maze,vector<vector<int>>& visited){\n        if(x==startX && y==startY) return false;\n        if( (x==0 || x==maze.size()-1 || y==0 || y==maze[0].size()-1) \n           && maze[x][y]!=\'+\')\n        {\n            return true;\n        }\n        return false;\n    }\n    \n    //main BFS function \n    int bfsHelper(vector<vector<char>>& maze,vector<vector<int>>& visited,int startX,int startY){\n        queue<vector<int>>Queue;\n        Queue.push({startX,startY,0});\n        while(!Queue.empty()){\n            int x = Queue.front()[0];\n            int y = Queue.front()[1];\n            int steps = Queue.front()[2];\n            Queue.pop();\n            //if you reach a valid exit, return the number of steps\n            if(isExit(x,y,startX,startY,maze,visited)) return steps;\n            int dx[4] = {0,-1,0,1};\n            int dy[4] = {-1,0,1,0};\n            //check in the 4 directions that you can travel\n            for(int i=0;i<4;i++){\n                int newX = x+dx[i] , newY = y+dy[i];\n                //if the coordinates of the cell are that of \n                //an unvisited valid empty cell, add it to the queue \n                //and mark it as visited.\n                if(isValid(newX,newY,maze.size(),maze[0].size(),maze,visited)){\n                    Queue.push({newX,newY,steps+1});\n                    visited[newX][newY] = 1;\n                }\n            }\n        }\n        //if you could not find a valid exit point, return -1\n        return -1;\n    }\n    \n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        int n = maze.size();\n        int m = maze[0].size();\n        //create a 2d matrix and mark all the cells as -1, \n        //denoting that they have not been visited yet.\n        vector<vector<int>>visited(n,vector<int>(m,-1));\n        return bfsHelper(maze,visited,entrance[0],entrance[1]);\n    }\n};\n```
['Breadth-First Search', 'Graph', 'C']