C++ || EASY || BFS
\nclass Solution {\npublic:\n    int dx[4] = {1 , -1, 0 ,0};\n    int dy[4] = { 0 ,0 , -1 ,1};\n    int nearestExit(vector<vector<char>>& maze, vector<int>& ent
```\nclass Solution {\npublic:\n    int dx[4] = {1 , -1, 0 ,0};\n    int dy[4] = { 0 ,0 , -1 ,1};\n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        \n        int n = maze.size() , m = maze[0].size();\n        queue<pair<int , int >> q;\n        vector<vector<bool>> visited(n , vector<bool>(m,0));\n        visited[entrance[0]][entrance[1]] = 1;\n        q.push({entrance[0] , entrance[1]});\n        int level = 0;\n        while( !q.empty() ) {\n            int siz = q.size();\n            level++;\n            while( siz-- ) {\n                pair<int , int > p = q.front();\n                q.pop();\n                for( int i=0; i<4; i++ ){\n                    int n_r = p.first+dx[i], n_c = p.second+dy[i];\n                    if( n_r>=0 && n_c>=0 && n_r<n && n_c<m && maze[n_r][n_c]==\'.\' && !visited[n_r][n_c]){\n                        if( n_r == 0 || n_c==0 || n_r == n-1 || n_c == m-1) return level;\n                        visited[n_r][n_c] = 1;\n                        q.push({n_r, n_c});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'Queue', 'C', 'Matrix']