C++ SOLUTION USING BFS
\nclass Solution {\npublic:\n    vector<int> r={0,0,-1,1};\n    vector<int> c={-1,1,0,0};\n    int nearestExit(vector<vector<char>>& ma, vector<int>& e) {\n    
```\nclass Solution {\npublic:\n    vector<int> r={0,0,-1,1};\n    vector<int> c={-1,1,0,0};\n    int nearestExit(vector<vector<char>>& ma, vector<int>& e) {\n        int n=ma.size(),m=ma[0].size(),res=0;\n        int s1=e[0],s2=e[1];\n        queue<pair<int,int>> q;\n        ma[s1][s2]=\'+\';\n        q.push({s1,s2});\n        while(!q.empty())\n        {\n            int s=q.size();\n            res++;\n            for(int k=0;k<s;k++)\n            {\n                auto j=q.front();\n                for(int p=0;p<4;p++)\n                {\n                    int p1=j.first+r[p],p2=j.second+c[p];\n                    if(p1<0||p2<0||p1>=n||p2>=m||ma[p1][p2]==\'+\')\n                        continue;\n                    if(p1==0||p2==0||p1==n-1||p2==m-1)\n                        return(res);\n                    ma[p1][p2]=\'+\';\n                    q.push({p1,p2});\n                }\n                q.pop();\n            }\n        }\n        return(-1);\n    }\n};\n```
[]