Simple BFS Solution | C++ without explanation
\nclass Solution {\npublic:\n    int nearestExit(vector<vector<char>>& m, vector<int>& e) \n    {\n        int r=size(m);\n        int c=size(m[0]); \n        i
```\nclass Solution {\npublic:\n    int nearestExit(vector<vector<char>>& m, vector<int>& e) \n    {\n        int r=size(m);\n        int c=size(m[0]); \n        int i=e[0];\n        int j=e[1];\n        queue<pair<int,int>> q;\n        int cnt=1;\n        if(i+1<r and m[i+1][j]==\'.\')\n        {\n            q.push({i+1,j});\n            m[i+1][j]=\'+\';\n        }\n        if(i-1>=0 and m[i-1][j]==\'.\')\n        {\n          q.push({i-1,j});\n            m[i-1][j]=\'+\';\n        }\n        if(j+1<c and m[i][j+1]==\'.\')\n        {\n            q.push({i,j+1});\n            m[i][j+1]=\'+\';\n        }\n        if(j-1>=0 and m[i][j-1]==\'.\')\n        {\n          q.push({i,j-1});\n            m[i][j-1]=\'+\';\n        }\n        m[i][j]=\'+\';\n        while(!q.empty())\n        {\n            int sz=q.size();\n            while(sz--)\n            {\n                auto front = q.front();\n                q.pop();\n                i=front.first;\n                j=front.second;\n                if(i==0 or j==0 or i==r-1 or j==c-1)\n                    return cnt;\n                if(i+1<r and m[i+1][j]==\'.\')\n                {\n                    q.push({i+1,j});\n                    m[i+1][j]=\'+\';\n                }\n                if(i-1>=0 and m[i-1][j]==\'.\')\n                {\n                  q.push({i-1,j});\n                    m[i-1][j]=\'+\';\n                }\n                if(j+1<c and m[i][j+1]==\'.\')\n                {\n                    q.push({i,j+1});\n                    m[i][j+1]=\'+\';\n                }\n                if(j-1>=0 and m[i][j-1]==\'.\')\n                {\n                  q.push({i,j-1});\n                    m[i][j-1]=\'+\';\n                }\n            }\n            cnt++;\n        }\n        return -1;\n        \n    }\n};\n```
[]