Beginner Brute force solution using sorting.
Approach\n Describe your approach to solving the problem. \n1. In STEP-1 we fill the array sequentially i.e., giving the elements indexes like that of a 2D arra
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. In <b>STEP-1</b> we fill the array sequentially i.e., giving the elements indexes like that of a 2D array :-> \n    ```\n    (0,0) (0,1) (0,2)\n    (1,0) (1,1) (1,2)\n    (2,0) (2,1) (2,2)\n\n2. After this we sort the array in STEP-2 on the basis of the distance between the cells from :->\n    ```\n    (rCenter, cCenter)\n    ```\n3. If the <b>j<sup>th</sup></b> cell distance from (rCenter,cCenter) which is measured using \n    ```\n    |r1 - rCenter| + |c1 - cCenter|\n    ```\n    is lesser than <b>(j-1)<sup>th</sup></b> cell distance from (rCenter,cCenter), we swap the two arrays i.e., bring the array which is closer to (rCenter, cCenter) forward.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$ O(m*n) $$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$ O(m*n) $$\n\n# Code\n```\nclass Solution {\n    public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n        int[][] arr = new int[rows*cols][2];\n        // variable to traverse through the array\n        int cntr = 0;\n        //  STEP-1\n        for(int i = 0; i < rows; i++){\n            for(int j = 0; j < cols; j++){\n                arr[cntr][0] = i;\n                arr[cntr++][1] = j;\n            } \n        }\n        // STEP-2\n        insertionSort(arr, rCenter, cCenter);\n        return arr;\n    }\n\n    public void insertionSort(int[][] arr, int rC, int cC){\n        for(int i = 0; i < arr.length - 1; i++){\n            for(int j = i + 1; j > 0; j--){\n                // STEP-3\n                if((Math.abs(arr[j][0] - rC) + Math.abs(arr[j][1] - cC)) < (Math.abs(arr[j - 1][0] - rC) + Math.abs(arr[j - 1][1] - cC))){\n                    swap(arr, j, j - 1);\n                }\n            }\n        }\n    }\n\n    public void swap(int[][] arr, int n1, int n2){\n        int[] temp = arr[n1];\n        arr[n1] = arr[n2];\n        arr[n2] = temp;\n    }\n}\n```\n\n#### <i>Any improvement or suggestion is welcomed</i> \uD83D\uDE4F\uD83C\uDFFB
['Sorting', 'Java']