Simple Java solution with Comparator
\tclass Solution {\n\t\tpublic int[][] allCellsDistOrder(int R, int C, int r0, int c0) {\n\t\t\tint[][] res = new int[R*C][1];\n\t\t\tint x =0;\n\t\t\tfor(int i
\tclass Solution {\n\t\tpublic int[][] allCellsDistOrder(int R, int C, int r0, int c0) {\n\t\t\tint[][] res = new int[R*C][1];\n\t\t\tint x =0;\n\t\t\tfor(int i=0;i<R;i++){\n\t\t\t\tfor(int j=0;j<C;j++){\n\t\t\t\t\tres[x++]= new int[]{i,j};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tArrays.sort(res,new Comparator<int[]>(){\n\t\t\t\tpublic int compare(int[] a,int[] b){\n\t\t\t\t\treturn (Math.abs(r0-a[0]) + Math.abs(c0-a[1]))-(Math.abs(r0-b[0]) + Math.abs(c0-b[1]));\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn res;\n\t\t}\n\t}
[]