Swift - Short and easy with sorted(), but slow. 100% memory
\n    func allCellsDistOrder(_ R: Int, _ C: Int, _ r0: Int, _ c0: Int) -> [[Int]] {\n        var grid = [[Int]]()\n        for i in 0..<R {\n            for j i
```\n    func allCellsDistOrder(_ R: Int, _ C: Int, _ r0: Int, _ c0: Int) -> [[Int]] {\n        var grid = [[Int]]()\n        for i in 0..<R {\n            for j in 0..<C {\n                grid.append([i, j])\n            }\n        }\n        \n        return grid.sorted { abs(r0 - $0[0]) + abs(c0 - $0[1]) < abs(r0 - $1[0]) + abs(c0 - $1[1]) }\n    }\n```
[]