Java Solution
\nclass Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int[][] res = new int[rows * cols][];\n        int
```\nclass Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int[][] res = new int[rows * cols][];\n        int k = 0;\n        res[k++] = new int[]{rStart, cStart};\n        int[] direction = {0, 1, 0, -1, 0};\n        int d = 0;\n        int len = 0;\n        while(k < rows * cols){\n            if(d == 0 || d == 2){\n                len++;\n            }\n            for(int i = 0; i < len; i++){\n                rStart += direction[d];\n                cStart += direction[d+1];\n                \n                if(rStart > -1 && rStart < rows && cStart > -1 && cStart < cols){\n                    res[k++] = new int[]{rStart, cStart};\n                }\n            }\n            d = ++d % 4;\n        }\n        return res;\n    }\n}\n```
['Array', 'Java']