Python straightforward DFS & BFS
\nclass Solution:\n    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:\n        def dfs(i, j):\n            seen.add((i, j))\n
```\nclass Solution:\n    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:\n        def dfs(i, j):\n            seen.add((i, j))\n            res.append([i, j])\n            for x, y in (i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1):\n                if 0 <= x < R and 0 <= y < C and (x, y) not in seen:\n                    dfs(x, y)\n        res, seen = [], set()\n        dfs(r0, c0)\n        return sorted(res, key = lambda x: abs(x[0] - r0) + abs(x[1] - c0))\n```\n```\nclass Solution:\n    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:\n        bfs, res, seen = [[r0, c0]], [], {(r0, c0)}\n        while bfs:\n            res += bfs\n            new = []\n            for i, j in bfs:\n                for x, y in (i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1):\n                    if 0 <= x < R and 0 <= y < C and (x, y) not in seen:\n                        seen.add((x, y))\n                        new.append([x, y])\n            bfs = new\n        return res\n```
['Depth-First Search', 'Breadth-First Search', 'Python']