Python Straightforward 5-Line O(N) Code
Go through the cells and classify them according to their distances towards (r0, c0). Finally, output them sequentially.\n\nclass Solution:\n    def allCellsDis
Go through the cells and classify them according to their distances towards `(r0, c0)`. Finally, output them sequentially.\n```\nclass Solution:\n    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:\n        res = [[] for _ in range(R + C)]\n        for row in range(R):\n            for col in range(C):\n                res[abs(row - r0) + abs(col - c0)].append([row, col])\n        return sum(res, [])\n```\n\nOf course, you can do it in one line with the builtin `sort`.\n```\nclass Solution:\n    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:\n        return sorted([[row, col] for row in range(R) for col in range(C)], key=lambda x: abs(x[0] - r0) + abs(x[1] - c0))\n```
['Python']