[Python | Go | Easy to understand] Because I'm a dummy, and so are you
This is a dummy\'s way to solve the problem so it might be a bit lengthy, but I figure this should be easy to understand.\n\nFirst look at the picture with the 
This is a dummy\'s way to solve the problem so it might be a bit lengthy, but I figure this should be easy to understand.\n\nFirst look at the picture with the arrows in the question (Look at the second example, it\'s easier to visualize).\n\nHere\'s the steps we follow:\n- First move 1 step to the right\n- Then move 1 step down\n- Then move 2 steps to the left\n- Then move 2 steps up\n- Then move 3 steps to the right\n- This goes on...\n\nHow can we exploit this pattern? By making a step variable.\n- If the step is odd, we move right then down\n- If the step is even, we move left then up\n\nFor each movement, we check if the position is within the matrix boundary. If it is, we add it to the solution, if not we ignore.\n\nJust look at the code. It\'s really simple.\n\nHere\'s the code:\n\n**Python:**\n```\nclass Solution:\n    def spiralMatrixIII(self, rows: int, cols: int, row: int, col: int) -> List[List[int]]:\n        step = 1\n        res = [[row, col]] # we always start with the given position\n        while len(res) < rows * cols: # stop when we have enough elements\n            if step % 2 == 1: # odd step\n                stop = col + step\n                while col < stop: # move left\n                    col += 1\n                    if self.is_valid(row, col, rows, cols):\n                        res.append([row, col])\n                \n                stop = row + step\n                while row < stop: # move down\n                    row += 1\n                    if self.is_valid(row, col, rows, cols):\n                        res.append([row, col])\n                \n            else: # even step\n                stop = col - step\n                while col > stop: # move right\n                    col -= 1\n                    if self.is_valid(row, col, rows, cols):\n                        res.append([row, col])\n                \n                stop = row - step\n                while row > stop: # move up\n                    row -= 1\n                    if self.is_valid(row, col, rows, cols):\n                        res.append([row, col])\n                \n            step += 1\n            \n        return res\n    \n    def is_valid(self, row, col, rows, cols):\n        return row >= 0 and row < rows and col >= 0 and col < cols\n```\n\n**Go:**\n```\nfunc spiralMatrixIII(rows int, cols int, row int, col int) [][]int {\n    step := 1\n    res := [][]int{[]int{row, col}}\n    \n    for len(res) < rows * cols {\n        if step % 2 == 1 { // odd step\n            stop := col + step\n            for col < stop { // move left\n                col++\n                if is_valid(row, col, rows, cols) {\n                    res = append(res, []int{row, col})\n                }\n            }\n            \n            stop = row + step\n            for row < stop { // move down\n                row++\n                if is_valid(row, col, rows, cols) {\n                    res = append(res, []int{row, col})\n                }\n            }\n        } else { // even step\n            stop := col - step\n            for col > stop { // move right\n                col--\n                if is_valid(row, col, rows, cols) {\n                    res = append(res, []int{row, col})\n                }\n            }\n            \n            stop = row - step\n            for row > stop { // move up\n                row--\n                if is_valid(row, col, rows, cols) {\n                    res = append(res, []int{row, col})\n                }\n            }\n        }\n        \n        step++\n    }\n    \n    return res\n}\n\nfunc is_valid(row, col, rows, cols int) bool {\n    return row >= 0 && row < rows && col >= 0 && col < cols\n}\n```
['Matrix', 'Python', 'Go']