Beats 95% || Easy to understand approach || C++
Intuition\nThe problem requires visiting all cells of a grid in a spiral order starting from a specified cell (rStart, cStart). The spiral pattern involves movi
# Intuition\nThe problem requires visiting all cells of a grid in a spiral order starting from a specified cell `(rStart, cStart)`. The spiral pattern involves moving right, down, left, and up repeatedly, expanding the boundaries of movement until all cells are visited.\n\n# Approach\n1. **Initialization:**\n    - Start from the given cell `(rStart, cStart)`.\n    - Define the initial boundaries: `top`, `bottom`, `left`, and `right` to track the limits of movement in each direction.\n2. **Spiral Movement:**\n    - **Move Right:** Start from the current position and move right until you reach the `right` boundary. After completing the movement, increase the `right` boundary by 1.\n    - **Move Down:** Move downwards until you reach the `bottom` boundary, then increase the `bottom` boundary by 1.\n    - **Move Left:** Move left until you reach the `left` boundary, then decrease the `left` boundary by 1.\n    - **Move Up:** Move upwards until you reach the `top` boundary, then decrease the `top` boundary by 1.\n3. **Boundary Checking:**\n    - During each movement (right, down, left, up), ensure that the current cell `(i, j)` is within the grid\'s boundaries `(0 <= i < rows and 0 <= j < cols)`. If it is, add it to the result.\n4. **Termination:**\n    - Continue the process until the number of visited cells equals rows * cols.\n# Complexity\n- Time complexity: $$O(rows\\times cols)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(rows\\times cols)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart,\n                                        int cStart) {\n        vector<vector<int>> ans;\n        int top = rStart - 1;\n        int bottom = rStart + 1;\n        int right = cStart + 1;\n        int left = cStart - 1;\n        int i = rStart;\n        int j = cStart;\n        while (ans.size() < (rows * cols)) {\n            // Move Right\n            while (j < right) {\n                if (j >= 0 && j < cols && i >= 0 && i < rows) {\n                    ans.push_back({i, j});\n                }\n                j++;\n            }\n            right++;\n            // Move Down\n            while (i < bottom) {\n                if (j >= 0 && j < cols && i >= 0 && i < rows) {\n                    ans.push_back({i, j});\n                }\n                i++;\n            }\n            bottom++;\n            // Move Left\n            while (j > left) {\n                if (j >= 0 && j < cols && i >= 0 && i < rows) {\n                    ans.push_back({i, j});\n                }\n                j--;\n            }\n            left--;\n            // Move Up\n            while (i > top) {\n                if (j >= 0 && j < cols && i >= 0 && i < rows) {\n                    ans.push_back({i, j});\n                }\n                i--;\n            }\n            top--;\n        }\n        return ans;\n        //Please Upvote\n    }\n};\n```
['Array', 'Matrix', 'C++']