C++ | Straightforward BFS | Faster than 91%
\nclass Solution {\npublic:\n    int m,n;\n    int dx[4] = {0,0,1,-1};\n    int dy[4] = {1,-1,0,0};\n    bool isBorder(int i,int j){\n        return (i==0 || i=
```\nclass Solution {\npublic:\n    int m,n;\n    int dx[4] = {0,0,1,-1};\n    int dy[4] = {1,-1,0,0};\n    bool isBorder(int i,int j){\n        return (i==0 || i==m-1 || j == 0 || j == n-1);\n    }\n    \n    bool valid(int r,int c){\n        return (r>=0 && c>=0 && r<m && c<n);\n    }\n    \n    int nearestExit(vector<vector<char>>& maze, vector<int>& ent) {\n        m = maze.size() , n=maze[0].size();\n        if(isBorder(ent[0] , ent[1]))  \n            maze[ent[0]][ent[1]] = \'+\';\n        int ans = 0;\n        queue<pair<int,int>> q;\n        q.push({ent[0],ent[1]});\n        while(!q.empty()){\n            int size = q.size();\n            for(int i=0;i<size;i++){\n                auto top = q.front();\n                q.pop();\n                int x = top.first , y = top.second;\n                if(maze[x][y] != \'+\' && isBorder(x,y))\n                    return ans;\n                for(int j=0;j<4;j++){\n                    int r = x + dx[j];\n                    int c = y + dy[j];\n                    if(valid(r,c) && maze[r][c]==\'.\'){\n                        q.push({r,c});\n                        maze[r][c] = \'*\';\n                    }\n                }\n            }\n            ans++;\n        }\n        return -1;\n    }\n};\n```
['Breadth-First Search', 'C', 'C++']