Java Solution Using Recursion faster than 99.43%
class Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int[][] ans = new int[rows*cols][2];\n        int to
class Solution {\n    public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        int[][] ans = new int[rows*cols][2];\n        int topr = rStart-1;\n        int bottomr =rStart+1;\n        int leftc = cStart-1;\n        int rightc =cStart+1;\n        ans[0][0] = rStart;\n        ans[0][1]= cStart;\n        \n        \n        return path(rows, cols, rStart, cStart, topr, bottomr, leftc, rightc, ans, 1);\n    }\n    int[][] path(int rows, int cols, int rStart, int cStart, int topr, int bottomr, int leftc, int rightc, int[][] mat, int x){\n        \n        if(topr<0 && bottomr>rows-1 && leftc<0 && rightc>cols-1){\n            return mat;\n        }\n        \n        for(int i = topr+1 ; i <= bottomr; i++){\n            if(i<rows && i>=0 && rightc>=0 && rightc<cols){\n                mat[x][0]=i;\n                mat[x][1]=rightc;\n                x +=1;\n            }\n        }\n        for(int i =rightc-1; i>= leftc ; i--){\n            if(i>=0 && i<cols && bottomr>=0 && bottomr < rows){\n                mat[x][0]=bottomr;\n                mat[x][1]=i;\n                x +=1;\n            }\n        }\n        for(int i =bottomr-1; i>=topr; i--){\n            if(i<rows && i>=0 && leftc >= 0 && leftc<cols){\n                mat[x][0]=i;\n                mat[x][1]=leftc;\n                x +=1;\n            }\n        }\n        for(int i = leftc+1 ; i<= rightc; i++){\n            if(i<cols && i>=0 && topr>=0 && topr<rows){\n                mat[x][0]=topr;\n                mat[x][1]=i;\n                x +=1;\n            }\n        }\n        return path(rows, cols, rStart+1, cStart, topr-1, bottomr+1, leftc-1, rightc+1, mat, x);\n            \n    }\n}
['Recursion', 'Java']