BEAUTIFUL CODE | BEATS 99% | ENUMS
Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int 
# Complexity\n- Time complexity: $$O(n^2)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n        vector<vector<int>> path = {{rStart, cStart}};\n        \n        enum dir { east, south, west, north };\n        int count = 2;\n\n        vector<int> dr = {0, 1, 0, -1};\n        vector<int> dc = {1, 0, -1, 0};\n\n        int curr_row = rStart;\n        int curr_col = cStart;\n        int curr_dir = east;\n\n        while (path.size() < rows * cols) {\n            for (int i = 0; i < count / 2; i++) {\n                curr_row += dr[curr_dir];\n                curr_col += dc[curr_dir];\n                if (0 <= curr_row && curr_row < rows && 0 <= curr_col && curr_col < cols) \n                    path.push_back({curr_row, curr_col});\n            }\n            count += 1;\n            curr_dir = (curr_dir + 1) % 4;\n        }\n\n\n        return path;\n        \n    }\n};\n```\n![aff812e9-9751-4e8c-be5f-636ebb5e4fa4_1712103254.png](https://assets.leetcode.com/users/images/d49ecd70-d79c-424c-9365-2befca1d4bb4_1723175039.8140182.png)
['C++']