Best Java Solution || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[][] allCellsDistOrder(int R, int C, int r0, int c0) {\n        int[][] result = new int[R * C][];\n        result[0] = new int[] {r0, c0};            // Add start point r0,c0 which has distance 0.\n        int resultIdx = 1;\n        int lim = Math.max( r0, R-r0-1 ) + Math.max( c0, C-c0-1 );\n\t\t                                           // lim is highest distance value.\n        for (int dist = 1; dist <= lim; dist++) {  // Process \'lim\' diamond-shapes having distance \'dist\'.\n            int r = r0 - dist;\n            int c = c0;\n            // Diamond side: Top Left\n            for (int count = dist; count > 0; count--) {    \n                if (r >= 0 && c >= 0)  result[resultIdx++] = new int[] {r, c};\n                r++;\n                c--;\n            }\n            \n            // Diamond side: Left Bottom\n            for (int count = dist; count > 0; count--) {\n                if (r < R && c >= 0)  result[resultIdx++] = new int[] {r, c};\n                r++;\n                c++;\n            }\n            \n            // Diamond side: Bottom Right\n            for (int count = dist; count > 0; count--) {\n                if (r < R && c < C)  result[resultIdx++] = new int[] {r, c};\n                r--;\n                c++;\n            }\n            \n            // Diamond side: Right Top\n            for (int count = dist; count > 0; count--) {\n                if (r >= 0 && c < C)  result[resultIdx++] = new int[] {r, c};\n                r--;\n                c--;\n            }\n        }\n        return result;\n    }\n}\n```
['Java']