Java | Easy | Sorting Solution
```class Solution {\n    public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n       int [][] ans = new int [rows*cols][2];\n      
```class Solution {\n    public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n       int [][] ans = new int [rows*cols][2];\n        // creating an 2d array to store coordinates / total pairs(i,j) \n        for(int i = 0; i < rows; i++)\n        {\n            for(int j = 0; j < cols; j++)\n            {\n                int bno = i * cols + j; //ans. array index\n                ans[bno][0] = i;\n                ans[bno][1] = j;\n            }\n        }\n        \n        Arrays.sort(ans,(a,b) ->{\n            int d1 = Math.abs(a[0] - rCenter) + Math.abs(a[1] - cCenter);\n            int d2 = Math.abs(b[0] - rCenter) + Math.abs(b[1] - cCenter);\n\n            return d1 - d2;\n        });\n            // (a,b) is each 1d array on ans array\'s index\n        return ans;\n    }\n}
[]