simple BFS || c++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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 {\nprivate:\n    void bfs(vector<vector<char>>& maze, int& i, int& j, vector<vector<bool>>& visited, int& ans, queue<pair<int, int>>& q) {\n        vector<int> row = {-1, 0, 1, 0};\n        vector<int> col = {0, 1, 0, -1};\n        int n = maze.size();\n        int m = maze[0].size();\n        int count = 0;\n\n        while (!q.empty()) {\n            int size = q.size();\n            count++;\n            for (int i = 0; i < size; i++) {\n                pair<int, int> p = q.front(); \n                q.pop(); \n                int a = p.first;\n                int b = p.second;\n\n                for (int k = 0; k < 4; k++) {\n                    int new_row = a + row[k];\n                    int new_col = b + col[k];\n                    \n                    if (new_row >= 0 && new_row < n && new_col >= 0 && new_col < m && !visited[new_row][new_col] && maze[new_row][new_col] == \'.\') {\n                        if (new_row == 0 || new_row == n - 1 || new_col == 0 || new_col == m - 1) {\n                            ans = count;\n                            return;\n                        }\n                        visited[new_row][new_col] = true;\n                        q.push({new_row, new_col});\n                    }\n                }\n            }\n        }\n    }\n\npublic:\n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        int i = entrance[0];\n        int j = entrance[1];\n        int n = maze.size();\n        int m = maze[0].size();\n        vector<vector<bool>> visited(n, vector<bool>(m, false));\n        visited[i][j] = true;\n\n        int ans = -1; // Use -1 to indicate no exit found\n        queue<pair<int, int>> q;\n        q.push({entrance[0], entrance[1]});\n        bfs(maze, i, j, visited, ans, q);\n\n        return ans;\n    }\n};\n\n```
['C++']