Easy to Understand Code in C++ with explanation
Approach\nIt is a simple BFS solution in which we are storing pair of indexes and its length from start in a queue and also a visited array to take care we not 
# Approach\nIt is a simple BFS solution in which we are storing pair of indexes and its length from start in a queue and also a visited array to take care we not again go to the same path and if we reach at the edge then we have to return the length.. \nBelow is my C++ code with 95% runtime\n\n\n# Code\n```\nclass Solution {\npublic:\n\n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        queue<pair<pair<int,int>,int>> q;\n        int n=maze.size();\n        int m=maze[0].size();\n        int x1=entrance[0];\n        int y1=entrance[1];\n        q.push({{x1,y1},0});\n        int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};\n        vector<vector<bool>> visited(n+1,vector<bool>(m+1,false));\n        while(!q.empty()){\n            pair<int,int> p=q.front().first;\n            int x=p.first;\n            int y=p.second;\n            visited[x][y]=true;\n            int len=q.front().second;\n            q.pop();\n            for(int i=0;i<4;i++){\n                int newx=x+dir[i][0];\n                int newy= y+dir[i][1];\n                if(newx>=0 && newy>=0 && newx<n && newy<m && maze[newx][newy]==\'.\' && !visited[newx][newy]){\n                // cout<<newx<<" "<<newy<<" "<<maze[newx][newy];\n                    visited[newx][newy]=true;\n                    q.push({{newx,newy},{len+1}});\n                    if(newx==0 || newy==0 || newx==n-1 || newy==m-1 ){\n                        // cout<<newx<<" "<<newy;\n                        return len+1;\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n};\n```\nPlease upvote if u like the solution :)
['Breadth-First Search', 'Graph', 'Queue', 'C++']