Java Sorting (Easy Understang)
\nclass Solution {\n    public int[][] allCellsDistOrder(int R, int C, int r0, int c0) {\n        int[][] res = new int[R*C][2];\n        int idx = 0;\n        
```\nclass Solution {\n    public int[][] allCellsDistOrder(int R, int C, int r0, int c0) {\n        int[][] res = new int[R*C][2];\n        int idx = 0;\n        for(int i = 0; i < R; i++){\n            for(int j = 0; j < C; j++){\n                res[idx][0] = i;\n                res[idx][1] = j;\n                idx++;\n            }        \n        }    \n        \n        Arrays.sort(res,(o1,o2)->\n           Math.abs(o1[0]-r0)+Math.abs(o1[1]-c0) - (Math.abs(o2[0]-r0) + Math.abs(o2[1]-c0))\n        );\n        \n        return res;\n    }\n}\n```
['Java']