Java straightforward solution
\n\tpublic int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        int[][] ret = new int[R*C][2];\n        int step = 1;\n        int i = 0;\n        i
```\n\tpublic int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        int[][] ret = new int[R*C][2];\n        int step = 1;\n        int i = 0;\n        int r = r0;\n        int c = c0;\n        int offset = 1;\n        while (i < R*C) {\n            for (int j = 0; j < step; j++) {\n                if (r >= 0 && c >= 0 && r < R && c < C && i < R*C) {\n                    ret[i][0] = r;\n                    ret[i][1] = c;\n                    i++;\n                }\n                c += offset;\n            }\n            for (int j = 0; j < step; j++) {\n                if (r >= 0 && c >= 0 && r < R && c < C && i < R*C) {\n                    ret[i][0] = r;\n                    ret[i][1] = c;\n                    i++;\n                }\n                r += offset;\n            }\n            step++;\n            offset = -offset;\n        }\n        return ret;\n    }\n```
[]