C++ BFS - Time: O(R*C) - Faster than 96.74%
We just have to run BFS algorithm starting at (r0, c0).\n\n\nclass Solution {\npublic:\n    vector<vector<int>> allCellsDistOrder(int R, int C, int r0, int c0) 
We just have to run BFS algorithm starting at (r0, c0).\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> allCellsDistOrder(int R, int C, int r0, int c0) {\n        vector<vector<int>> m;\n        m.reserve(R * C);\n        \n        queue<pair<int, int>> q;\n            \n        q.push({r0, c0});\n        bool v [100][100];\n        memset(v, 0, sizeof(v));\n        v[r0][c0] = true;\n        \n        pair<int, int> n[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n        while (!q.empty()) {\n            pair<int, int> u = q.front();\n            q.pop();\n\n            m.push_back({u.first, u.second});\n            \n            for (const auto& p: n) {\n                auto w = make_pair(u.first + p.first, u.second + p.second);\n                if (w.first >= 0 && w.first < R && w.second >= 0 && w.second < C && !v[w.first][w.second]) {\n                    v[w.first][w.second] = true;\n                    q.push({w.first, w.second});\n                }\n            }\n        }\n        \n        return m;\n    }\n};\n```
['Breadth-First Search', 'C']