Java | 5 liner | Simple
T/S: O(rows x cols)/O(rows x cols)\n\npublic int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\tvar triplets = new ArrayList<List<Inte
**T/S:** O(rows x cols)/O(rows x cols)\n```\npublic int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\tvar triplets = new ArrayList<List<Integer>>(rows * cols);\n\tvar ordered = new int[distances.size()][2];\n\n\t// create triplets of (row, column, distance)\n\tfor (var i = 0; i < rows; i++)\n\t\tfor (var j = 0; j < cols; j++)\n\t\t\ttriplets.add(List.of(i, j, Math.abs(rCenter - i) + Math.abs(cCenter - j)));\n\n\t// sort triplets by distance\n\ttriplets.sort(Comparator.comparingInt(cell -> cell.get(2)));\n\n\treturn triplets.stream()\n\t\t\t\t   .map(triplets -> new int[]{triplet.get(0), triplet.get(1)})\n\t\t\t\t   .toArray(int[][]::new);\n}\n```\n***Please upvote if this helps***
['Java']