C++ - Commented Solution
Intuition\nThe below code works like this:\n\n\nstartPos {Row, Col}\nloop 1:\nCol -> + 1, Row -> + 0\nCol -> + 0, Row -> + 1\n++ Counter\nloop 2:\nCol -> - 1, R
# Intuition\nThe below code works like this:\n\n```\nstartPos {Row, Col}\nloop 1:\nCol -> + 1, Row -> + 0\nCol -> + 0, Row -> + 1\n++ Counter\nloop 2:\nCol -> - 1, Row -> + 0\nCol -> - 1, Row -> + 0\nCol -> + 0, Row -> - 1\nCol -> + 0, Row -> - 1\n++ Counter\n...\n```\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        vector<vector<int>> result;\n        vector<int> startPos {rStart, cStart};\n        result.push_back(startPos);\n\n        // For each walk, firstly we move the column by ""counter"" steps,\n        //                secondly we move the row by ""counter"" steps,\n        // Note that the step direction will depend on the "counter % 2 == 0"\n        int counter {1};\n        while(result.size() != rows * cols) {\n            for (int i = 1; i <= counter; ++ i) {\n                startPos[1] = startPos[1] + (counter % 2 == 0 ? -1 : 1);\n                if (startPos[1] >= 0 && startPos[0] >= 0 && startPos[1] < cols && startPos[0] < rows)\n                    result.push_back(startPos);\n            }\n\n            for (int i = 1; i <= counter; ++ i) {\n                startPos[0] = startPos[0] + (counter % 2 == 0 ? -1 : 1);\n                if (startPos[1] >= 0 && startPos[0] >= 0 && startPos[1] < cols && startPos[0] < rows)\n                    result.push_back(startPos);\n            }\n            \n            ++ counter;\n        }\n\n        return result;\n    }\n};\n```
['C++']