Easy C++ Solution
In the below algorithm, I have used direction parameters :\n(0,1) for east\n(1,0) for south\n(0,-1) for west\n(-1,0) for north\n\nEven there is a chance of gett
In the below algorithm, I have used direction parameters :\n(0,1) for east\n(1,0) for south\n(0,-1) for west\n(-1,0) for north\n\nEven there is a chance of getting out of the boundary, this algorithm works fine only because of this statement:\n```\nif(rStart>=0 && rStart<rows && cStart>=0 && cStart<cols){\n                    result.push_back({rStart,cStart});\n                }\n```\n\n\nComplete Code:-\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        \n        vector<vector<int>> result = {{rStart,cStart}};\n        \n        vector<vector<int>> dir = {{0,1},{1,0},{0,-1},{-1,0}};\n        \n        int len = 0, d = 0;\n        \n        while(result.size()<rows*cols){\n            \n            if(d==0 || d==2) len++;\n            \n            for(int i=0;i<len;i++){\n                rStart+=dir[d][0];\n                cStart+=dir[d][1];\n                if(rStart>=0 && rStart<rows && cStart>=0 && cStart<cols){\n                    result.push_back({rStart,cStart});\n                }\n            }\n            d = (d+1)%4;\n        }\n        return result;\n    }\n};\n```\nKindly upvote if you get any help here.\nHappy coding!
['C']