Easy to understand java solution
\nclass Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        // {0,1,0,-1,0}   directions  0-> col++, 1->row++,
```\nclass Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        // {0,1,0,-1,0}   directions  0-> col++, 1->row++, 2-> col-- 3->row--\n        \n        \n        int directions[]={0,1,0,-1,0} ;\n        \n        int steps=0;\n        int move=0;\n        int count=0;\n        int ans[][]=new int[rows*cols][2];\n        ans[count][0]=rStart;\n        ans[count][1]=cStart;\n        count++;\n        \n        int row=rStart,col=cStart;\n        \n        while(count<rows*cols)\n        {\n            if(move==0 || move== 2)\n                steps++;\n            \n            for(int i=0;i<steps;i++)\n            {\n                row+=directions[move];\n                col+=directions[move+1];\n               if(row<rows && row>=0 && col<cols && col>=0)\n               {\n                ans[count][0]=row;\n                ans[count][1]=col;\n                count++;\n               }\n                \n            }\n            if(move!=0)\n            move=(move+1)%4;\n            else \n                move++;\n        }\n        \n        \n        return ans;\n        \n        \n        \n        \n        \n    }\n    \n}\n```
['Java']