Easy and intuitive approach
Intuition\n Describe your first thoughts on how to solve this problem. \nSimulating the process\n\n\n# Complexity\n- Time complexity:\n O(cols * rows)\n Add you
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimulating the process\n\n\n# Complexity\n- Time complexity:\n O(cols * rows)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n  \n- Space complexity:\n  O(cols * rows * rows * cols)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n        vector<vector<int>> ans;\n        vector<vector<int>> dir;\n        // R, D, L, U \n        dir.push_back({0,1});\n        dir.push_back({1,0});\n        dir.push_back({0,-1});\n        dir.push_back({-1,0});\n        vector<int> limit={1,1,2,2};\n        int curDir=0;\n        int j=0;\n        while(ans.size() < (rows * cols) )\n        {   \n            vector<int> D=dir[curDir];\n            int l=0;\n            // ans.push_back({rStart,cStart});\n\n            while(l<limit[curDir])\n            {\n                // if(ans.back()[0]!=rStart&&ans.back()[1])\n                if(rStart<rows&&rStart>=0&&cStart<cols&&cStart>=0)\n                    ans.push_back({rStart,cStart});\n                rStart+=D[0];\n                cStart+=D[1];\n                l++;\n                j++;\n                // cout <<rStart<<" "<<cStart<<endl;\n            }\n            limit[curDir]+=2;\n            curDir++;\n            curDir=curDir%4;\n        }\n        return ans;\n        \n        \n    }\n};\n```
['Simulation', 'C++']