Solution
C++ []\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        \n        ios_base::sync_with_
```C++ []\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        \n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n        cout.tie(NULL);\n\n        vector<vector<int>> result;\n        int total = 0;\n\n        int rowStart = rStart;\n        int rowEnd = rStart;\n\n        int colStart = cStart;\n        int colEnd = cStart;\n\n        while(true){\n            for(int i=colStart; i<=colEnd; i++){\n                if(i >= 0 && i < cols && rowStart >= 0){\n                    result.push_back({rowStart, i});\n                    total++;\n                }\n            }\n            colEnd++;\n            if(total == (rows * cols))\n                break;\n            for(int i=rowStart; i<=rowEnd; i++){\n                if(i >= 0 && i < rows && colEnd < cols){\n                    result.push_back({i, colEnd});\n                    total++;\n                }\n            }\n            rowEnd++;\n            if(total == (rows * cols))\n                break;\n            for(int i=colEnd; i>=colStart; i--){\n                if(i >= 0 && i < cols && rowEnd < rows){\n                    result.push_back({rowEnd, i});\n                    total++;\n                }\n            }\n            colStart--;\n            if(total == (rows * cols))\n                break;\n            for(int i=rowEnd; i>=rowStart; i--){\n                if(i >= 0 && i < rows && colStart >= 0){\n                    result.push_back({i, colStart});\n                    total++;\n                }\n            }\n            rowStart--;\n            if(total == (rows * cols))\n                break;\n        }\n        return result;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:\n        visits = []\n        top, bottom, left, right = rStart, rStart + 1, cStart, cStart + 1\n\n        self.incr = 1\n        direction = 0\n\n        def place(row, col):\n            visits.append([row, col])\n            self.incr += 1\n        \n        while self.incr != (1 + rows * cols):\n            if direction == 0:\n                if top >= 0:\n                    row = top\n                    for col in range(max(left, 0), min(right, cols)):\n                        place(row, col)\n                right += 1\n            if direction == 1:\n                if right <= cols:\n                    col = right - 1\n                    for row in range(max(top, 0), min(bottom, rows)):\n                        place(row, col)\n                bottom += 1\n            if direction == 2:\n                if bottom <= rows:\n                    row = bottom - 1\n                    for col in range(min(right - 1, cols - 1), max(left - 1, -1), -1):\n                        place(row, col)\n                left -= 1\n            if direction == 3:\n                if left >= 0:\n                    col = left\n                    for row in range(min(bottom - 1, rows - 1), max(top - 1, -1), -1):\n                        place(row, col)\n                top -= 1\n            direction = (direction + 1) % 4\n        return visits\n```\n\n```Java []\nclass Solution {\n    int index = 1;\n    int row;\n    int col;\n    int rows;\n    int cols;\n\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int[][] result = new int[rows * cols][2];\n        int moves = 0;\n        row = rStart;\n        col = cStart;\n        this.rows = rows;\n        this.cols = cols;\n        result[0] = new int[] { rStart, cStart };\n        while (index < result.length) {\n            ++moves;\n            addToResult(result, moves, 1, 0);\n            addToResult(result, moves, 0, 1);\n            ++moves;\n            addToResult(result, moves, -1, 0);\n            addToResult(result, moves, 0, -1);\n        }\n        return result;\n    }\n    public void addToResult(int[][] result, int moves, int horizontal, int vertical) {\n        for (int i = 0; i < moves; ++i) {\n            row += vertical;\n            col += horizontal;\n            if (row < rows && row > -1 && col < cols && col > -1) {\n                result[index] = new int[] { row, col };\n                ++index;\n            }\n        }\n    }\n}\n```\n
['C++', 'Java', 'Python3']