Clean code
\n# Complexity\n- Time complexity: O(max(rows, cols))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, 
\n# Complexity\n- Time complexity: O(max(rows, cols))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# ----  UPVOTE  ----\n# Code\n```\nclass Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int res[][] = new int[rows*cols][2];\n        int direc[][] = {{0,1}, {1,0}, {0,-1}, {-1,0}};\n        int idx = 0, count = 1, steps = 1;\n        res[0][0] = rStart;\n        res[0][1] = cStart;\n\n        while (count < (rows*cols)) {\n            for (int i = 0; i < 2; i++) {\n                int dr = direc[idx%4][0];\n                int dc = direc[idx%4][1];\n                for (int j = 0; j < steps; j++) {\n                    rStart += dr;\n                    cStart += dc;\n                    if (rStart >= 0 && rStart < rows && cStart >= 0 && cStart < cols) {\n                        res[count][0] = rStart;\n                        res[count][1] = cStart;\n                        count++;\n                    }\n                }\n                idx++;\n            }\n            steps++;\n        }\n        return res;\n    }\n}\n```\n
['Array', 'Matrix', 'Simulation', 'Java']