BFS
C++\ncpp\nint dir[5] = {0, -1, 0, 1, 0};\nint nearestExit(vector<vector<char>>& m, vector<int>& ent) {\n    queue<array<int, 3>> q; // i, j, steps\n    q.push({
**C++**\n```cpp\nint dir[5] = {0, -1, 0, 1, 0};\nint nearestExit(vector<vector<char>>& m, vector<int>& ent) {\n    queue<array<int, 3>> q; // i, j, steps\n    q.push({ent[0], ent[1], 0});\n    while(!q.empty()) {\n        auto [i, j, steps] = q.front(); q.pop();\n        if ((i != ent[0] || j != ent[1]) && (i == 0 || j == 0 || i == m.size() - 1 || j == m[i].size() - 1))\n            return steps;\n        for (int d = 0; d < 4; ++d) {\n            int di = i + dir[d], dj = j + dir[d + 1];\n            if (di >= 0 && dj >= 0 && di < m.size() && dj < m[di].size() && m[di][dj] == \'.\') {\n                m[di][dj] = \'+\';\n                q.push({di, dj, steps + 1});\n            }\n        }\n    }\n    return -1;\n}\n```
[]