Easy to understand Beginner friendly python solution || 2 min read
Intuition\n Describe your first thoughts on how to solve this problem. \nRead the approach step by step, and look into the code.\n\n\n# Approach\n Describe your
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nRead the approach step by step, and look into the code.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere, our approach will be to move one step right,one step down,one step left and one step up.... UNLESS... we already have that row/col in our visited sets. \n\nWe traverse in a particular direction until we find that row/col in our hashsets.\n\nAnd then, once you\'re done with the traversal in a particular direction, check if it is in bounds and append it to the answer which you will be returning.\n\nRepeat this process until the len of the array you are returning is less than the product of rows and columns.\n\n( SEE THE CODE ) !!! now.\n\n\n\n# Code\n```\nclass Solution:\n    def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:\n        def inBounds(x,y):\n            return 0 <= x < rows and 0 <= y < cols\n        ver,hor = set(),set()\n        res = []\n        currRow = rStart\n        currCol = cStart\n        hor.add(rStart)\n        ver.add(cStart)\n        res.append((rStart,cStart))\n        while len(res) != rows*cols:\n            while currCol in ver:\n                if inBounds(currRow,currCol+1):\n                    res.append((currRow,currCol+1))\n                currCol += 1\n            ver.add(currCol)\n            while currRow in hor:\n                if inBounds(currRow+1,currCol):\n                    res.append((currRow+1,currCol))\n                currRow += 1\n            hor.add(currRow)\n            while currCol in ver:\n                if inBounds(currRow,currCol-1):\n                    res.append((currRow,currCol-1))\n                currCol -= 1\n            ver.add(currCol)\n            while currRow in hor:\n                if inBounds(currRow-1,currCol):\n                    res.append((currRow-1,currCol))\n                currRow -= 1\n            hor.add(currRow)\n        return res\n\n\n\n```
['Python3']