Simple BFS (C++) code
\nclass Solution\n{\n\tqueue<pair<int, int>> q1;\n\tvector<vector<int>> visited;\n\tint bfs(vector<vector<char>> &grid, int i, int j, vector<vector<int>> visi)\
```\nclass Solution\n{\n\tqueue<pair<int, int>> q1;\n\tvector<vector<int>> visited;\n\tint bfs(vector<vector<char>> &grid, int i, int j, vector<vector<int>> visi)\n\t{\n\t\tint xn[] = {1, -1, 0, 0};\n\t\tint yn[] = {0, 0, -1, 1};\n\t\tqueue<pair<int, int>> q;\n\t\tvisited[i][j] = 1;\n\t\tq.push({i, j});\n\t\tq1.push({i, j});\n\t\tint ans = INT_MAX;\n\t\twhile (!q.empty())\n\t\t{\n\t\t\tint x = q.front().first;\n\t\t\tint y = q.front().second;\n\t\t\tq.pop();\n\n\t\t\tfor (int i1 = 0; i1 < 4; i1++)\n\t\t\t{\n\t\t\t\ti = x + xn[i1];\n\t\t\t\tj = y + yn[i1];\n\t\t\t\tif (i >= grid.size() || j >= grid[0].size() || grid[i][j] == \'+\' || visited[i][j] == 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tvisi[i][j] = visi[x][y] + 1;\n\t\t\t\tvisited[i][j] = 1;\n\t\t\t\tq.push({i, j});\n\t\t\t\tq1.push({i, j});\n\t\t\t\tif (i == 0 || i == grid.size() - 1 || j == 0 || j == grid[0].size() - 1)\n\t\t\t\t\tans = min(visi[i][j], ans);\n\t\t\t\t\t\t}\n\t\t}\n\t\tif (ans == INT_MAX)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn ans - 1;\n\t}\n\npublic:\n\tint nearestExit(vector<vector<char>> &maze, vector<int> &e)\n\t{\n\t\tint i = e[0];\n\t\tint j = e[1];\n\n\t\tvector<vector<int>> visi;\n\n\t\tint xn[] = {1, -1, 0, 0};\n\t\tint yn[] = {0, 0, -1, 1};\n\n\t\tint n = maze.size();\n\t\tint m = maze[0].size();\n\t\tvisited.resize(n + 1, vector<int>(m + 1, 0));\n\n\t\tvisi.resize(n + 1, vector<int>(m + 1, 0));\n\t\tvisi[i][j] = 1;\n\t\treturn bfs(maze, i, j, visi);\n\t}\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Queue', 'C', 'C++']