C++ || BFS || GOOD EXPLAINED CODE || EASY
\n*************************************** DON\'T FORGET TO UPVOTE*****************************************\n\n\nclass Solution {\npublic:\n    // APPROACH : BAS
```\n*************************************** DON\'T FORGET TO UPVOTE*****************************************\n\n\nclass Solution {\npublic:\n    // APPROACH : BASIC APPLIED BFS ALGORITHM\n    //            T(O)=O(linear)    &&    S(O)=O(linear)\n    \n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        \n        int n = maze.size();\n        int m = maze[0].size();\n        int er = entrance[0];\n        int ec = entrance[1];\n        \n        //helping data structures\n        vector<vector<bool>> vis(n, vector<bool> (m, false));\n        vector<int> drow {0, -1, 0, 1};\n        vector<int> dcol {-1, 0, 1, 0};\n        \n        // queue<steps, (row,col) >\n        queue<pair<int,pair<int,int>>> q;\n\n        // pushing in entrance cell with steps = 0 \n        q.push({0,{er,ec}});\n        vis[er][ec] = true;\n         \n        while(!q.empty())   {\n            auto it = q.front();\n            q.pop();\n            int steps = it.first;\n            int r = it.second.first;\n            int c = it.second.second;\n            \n            for(int i=0; i<4; i++)  {\n                int dr = r+drow[i];\n                int dc = c+dcol[i];\n                \n                //check if its a legal move or not\n                if(dr>=0&&dr<n&&dc>=0&&dc<m&&vis[dr][dc]==false&&maze[dr][dc]==\'.\') {\n                    //exit cell\n                    if(dr==n-1 || dr==0 || dc==m-1 || dc==0 ) {       \n                        if(dr!=er || dc!=ec )       //checking if its entrance cell \n                            return steps+1;\n                    }\n                    \n                    q.push({steps+1, {dr,dc}});\n                    vis[dr][dc]=true;\n                }\n            }\n        }\n        \n        return -1;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'Queue', 'C', 'C++']