Java: Solution using simple walking simulation (97%)
\nclass Solution {\n    public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        final int totalCellsToVisit = R * C;\n        final int[][] cell
```\nclass Solution {\n    public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        final int totalCellsToVisit = R * C;\n        final int[][] cells = new int[totalCellsToVisit][2];\n        int cellsVisited = 0;\n        int stepLength = 1;\n        int stepsTaken = 0;\n        int direction = 0;\n        int row = r0, column = c0;\n        \n        while (cellsVisited < totalCellsToVisit) {\n            // If we are inside the matrix, record the position\n            if (row >= 0 && row < R && column >= 0 && column < C) {\n                cells[cellsVisited][0] = row;\n                cells[cellsVisited][1] = column;\n                cellsVisited++;\n            }\n            \n            // Move a step to correct direction (0=E, 1=S, 2=W, 3=N)\n            if (direction == 0) { column++; }\n            else if (direction == 1) { row++; }\n            else if (direction == 2) { column--; }\n            else if (direction == 3) { row--; }\n            stepsTaken++;\n            \n            // If we are taken the correct amount of steps to the current direction,\n            // change direction\n            if (stepsTaken == stepLength) {\n                stepsTaken = 0;\n                direction++;\n                // When going east or west increase the steps we take for each direction\n                if (direction == 2) {\n                    stepLength++;\n                    stepsTaken = 0;\n                } else if (direction == 4) {\n                    direction = 0;\n                    stepLength++;\n                    stepsTaken = 0;\n                }\n            }\n        }\n        return cells;\n    }\n}\n```
['Java']