Just Simulate ||  Most easy to understand solution || Beats 100%
Intuition\nJust try to simulate for an smaller matrix and try to find the pattern it is following and then just simulate the pattern.\n\n# Approach\n\nInitializ
# Intuition\nJust try to simulate for an smaller matrix and try to find the pattern it is following and then just simulate the pattern.\n\n# Approach\n\n**Initialization:**\n\nStore the given starting position in the final answer.\nSet **jump** to 0 (this represents the number of steps needed to traverse in each direction).\n\n**Simulation Loop:**\n\n**Step 0:** Check if all positions in the matrix have been visited.\n\n**Step 1:** Increment **jump** by 1.\n\n**Step 2:** Move east **jump** number of times.\n\n**Step 3:** Move south **jump** number of times.\n\n**Step 4:** Increment **jump** by 1.\n\n**Step 5:** Move west **jump** number of times.\n\n**Step 6:** Move north **jump** number of times.\n\n**Step 7:** Return to Step 0.\n\n# Complexity\n- Time complexity:\n  **Best case :** O(rows * cols);\n  **Worst Case :** O(4 * rows * cols);\n\n# Code\n```\nclass Solution {\n\n    int x=0,y=0,pos=0;\n    int dirs[][]={{1,0},{0,-1},{-1,0},{0,1}};\n\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n        int[][] ans=new int[rows*cols][2];\n\n        ans[pos][0]=rStart;\n        ans[pos][1]=cStart;\n\n        pos++;\n\n        x=rStart;\n        y=cStart;\n        \n        int jumps=0;\n\n        while(pos<rows*cols)\n        {\n            jumps++;\n            help(rows,cols,jumps,ans,3);\n            help(rows,cols,jumps,ans,0);\n\n            jumps++;\n\n            help(rows,cols,jumps,ans,1);\n            help(rows,cols,jumps,ans,2);\n        }\n        return ans;\n    }\n\n    public void help(int n,int m,int jump,int[][] ans,int ind)\n    {\n        while(jump--!=0)\n        {\n            x+=dirs[ind][0];\n            y+=dirs[ind][1];\n\n            if(x<n && y<m && x>-1 && y>-1)\n            {\n                ans[pos][0]=x;\n                ans[pos][1]=y;\n                pos++;\n            }\n        }\n    }\n}\n\n```\n\n![Upvote Image.jpg](https://assets.leetcode.com/users/images/9ca8dbc5-4129-4ae6-9071-5a859071d63e_1723085334.0256407.png)\n
['Simulation', 'Java']