C#
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\npublic class Solution {\n    public int[][] SpiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        List<int[]> result = new();\n       int[,] directions = new int[,]{{0,1} ,{1,0},{0,-1},{-1,0}};\n        int len =0;\n        int d =0;\n        result.Add(new int[]{rStart, cStart});\n\n        while(result.Count < rows * cols)\n        {\n            //directions right---> or left <---, increase len++\n            if(d==0 || d==2)\n            {\n                len++;\n            }\n            for(int k=0; k<len; k++)\n            {\n                rStart += directions[d,0];\n                cStart += directions[d,1];\n                if(rStart < rows && rStart >=0 && cStart < cols && cStart >=0)\n                {\n                    result.Add(new int[]{rStart, cStart});\n                }\n            }\n            d= (d+1) % 4;\n        }\n        return result.ToArray();\n    }\n}\n```
['C#']