Java Solution
Code\n\nclass Solution {\n    int idx;\n    int[][] ret;\n    \n    private void add (int r, int c, int R, int C) {\n        if (r >= R || r < 0 || c >= C || c 
# Code\n```\nclass Solution {\n    int idx;\n    int[][] ret;\n    \n    private void add (int r, int c, int R, int C) {\n        if (r >= R || r < 0 || c >= C || c < 0) return;\n        ret[idx][0] = r;\n        ret[idx++][1] = c;\n    }\n    \n    public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        int r = r0, c = c0, len = 1;\n        ret = new int[R * C][2];\n        while (idx < (R * C )) {         \n            for (int k = 0; k < len; k++) add(r, c++, R, C);          \n            for (int k = 0; k < len; k++) add(r++, c, R, C);\n            len++;\n            for (int k = 0; k < len; k++) add(r, c--, R, C);\n            for (int k = 0; k < len; k++) add(r--, c, R, C);\n            len++;   \n        }\n        return ret;\n    }\n}\n```
['Java']