Simple C++ solution.. striver type approach ..simple bfs ..
Intuition\n Describe your first thoughts on how to solve this problem. \neverything is explained in code comments\n\n# Approach\n Describe your approach to solv
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\neverything is explained in code comments\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n        int m=maze.size();\n        int n=maze[0].size();\n        // queue of pair of pair {steps,{row,col}}\n        queue<pair<int,pair<int,int>>> q;\n        //starting from intital row and column\n        //instead of using visited matrix we can change maze from \'.\' -> \'+\' ...to mark visitec\n\n        q.push({0,{e[0],e[1]}});\n        // travelling in all 4 directions\n        int dr[]={-1,1,0,0};\n        int dc[]={0,0,-1,1};\n        maze[e[0]][e[1]]=\'+\';\n        while(!q.empty()){\n            auto it=q.front();\n            q.pop();\n           \n            int steps=it.first;\n            int row=it.second.first;\n            int col=it.second.second;\n            //checking if the row,col is border or not.. \n            //steps!=0 check if it was not intial\n            if((row==0||col==0||row==m-1||col==n-1)&&steps!=0) {\n                cout<<row<<" "<<col<<endl;\n                return steps;\n            }\n            for(int i=0;i<4;i++){\n                int nrow=row+dr[i];\n                int ncol=col+dc[i];\n                if(nrow>=0&&ncol>=0&&nrow<m&&ncol<n&&maze[nrow][ncol]==\'.\'){\n                    q.push({steps+1,{nrow,ncol}});\n                    maze[nrow][ncol]=\'+\';\n                }\n            }\n        }\n        // couldn\'t find any exit\n        return -1;\n    }\n};\n```
['C++']