Solution made easy!
Approach\nSame as Spiral Matrix 1\nJust keep in mind that we do not have to stop once we are out of the boundary. The stopping condition is that when we have vi
# Approach\nSame as Spiral Matrix 1\nJust keep in mind that we do not have to stop once we are out of the boundary. The stopping condition is that when we have visited all the cells i.e. $$ans.size() == m*n$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int m, int n, int x, int y) {\n        vector<vector<int>> ans;\n\n        int len = 1;\n        ans.push_back({x,y});\n\n        while(ans.size() < m*n) {\n            for(int j=1 ; j<=len ; j++) {\n                if(isValid(x,y+j,m,n)) {\n                    ans.push_back({x,y+j});\n                }\n            }\n            y += len;\n            \n            for(int i=1 ; i<=len ; i++) {\n                if(isValid(x+i,y,m,n)) {\n                    ans.push_back({x+i,y});\n                }\n            }\n            x += len;\n\n            len++;\n            for(int j=1 ; j<=len ; j++) {\n                if(isValid(x,y-j,m,n)) {\n                    ans.push_back({x,y-j});\n                }\n            }\n            y -= len;\n\n            for(int i=1 ; i<=len ; i++) {\n                if(isValid(x-i,y,m,n)) {\n                    ans.push_back({x-i,y});\n                }\n            }\n            x -= len;\n            len++;\n        }\n        return ans;\n    }\n\n    bool isValid(int i, int j, int m, int n) {\n        return (i>=0 && j>=0 && i<m && j<n);\n    }\n};\n```\n\nCheck all the Spiral Matrix Problems (1 to 4) here -\nSpiral Matrix 1 - https://leetcode.com/problems/spiral-matrix/solutions/3747955/easy-traversal/\nSpiral Matrix 2 - https://leetcode.com/problems/spiral-matrix-ii/solutions/3747970/same-as-spiral-matrix-i/\nSpiral Matrix 3 - https://leetcode.com/problems/spiral-matrix-iii/solutions/3750377/solution-made-easy/\nSpiral Matrix 4 - https://leetcode.com/problems/spiral-matrix-iv/solutions/2230030/simple-solution/\n
['C++']