C
\n\nint** spiralMatrixIII(int rows, int cols, int rStart, int cStart, int* returnSize, int** returnColumnSizes) {\n    (*returnSize) = rows * cols;\n    *return
![image](https://assets.leetcode.com/users/images/689bb355-4bde-4d86-bac1-13b88f5cb601_1654783840.3640954.png)\n```\nint** spiralMatrixIII(int rows, int cols, int rStart, int cStart, int* returnSize, int** returnColumnSizes) {\n    (*returnSize) = rows * cols;\n    *returnColumnSizes = (int*) malloc((*returnSize) * sizeof(int));\n    int** res = (int**) malloc((*returnSize) * sizeof(int*));\n    for (int i = 0; i < (*returnSize); i++) {\n        res[i] = (int*) calloc(2, sizeof(int));\n        (*returnColumnSizes)[i] = 2;\n    }\n    res[0][0] = rStart; res[0][1] = cStart;\n    int up = 1, right = 1, cntRL = 0, cntUD = 0, idx = 1;\n    while (idx < (*returnSize)) {\n        for (int shift = 1; shift <= right; shift++) {\n            cStart = (cntRL % 2 == 0) ? cStart + 1 : cStart - 1;\n            if (rStart < rows && cStart < cols && rStart > -1 && cStart > -1) {\n                res[idx][0] = rStart;\n                res[idx][1] = cStart;\n                idx++;\n            }\n        }\n        cntRL++;\n        right++;\n        for (int shift = 1; shift <= up; shift++) {\n            rStart = (cntUD % 2 == 0) ? rStart + 1 : rStart - 1;\n            if (rStart < rows && cStart < cols && rStart > -1 && cStart > -1) {\n                res[idx][0] = rStart;\n                res[idx][1] = cStart;\n                idx++;\n            }\n        }\n        cntUD++;\n        up++;\n    }\n    return res;\n}\n```
['C']