Python 3   ||   11 lines,  w/ explanation   ||   T/S: 94% / 99%
Here\'s the plan:\n1. We pad the top and bottom of the grid with rows ofinf to avoid having to test whether we remain in the grid.\n1. We start in the 2nd colum
Here\'s the plan:\n1. We pad the top and bottom of the grid with rows of`inf` to avoid having to test whether we remain in the grid.\n1. We start in the 2nd column (1-indexed) and look back to the 1st column and iterate by cell down the column. We repat this iteration left-to-right.\n1. For each cell in the column, we check the`min`of three cells in the previous column that could move to that cell. If`min` is not greater than the  cell\'s value, then that cell cannot be visited, and we change the cell\'s value to`inf`.\n1. When we either reach the last column of`grid` or we have a column in which every cell has value`inf`, we return the last visited column.\n```\nclass Solution:\n    def maxMoves(self, grid: List[List[int]]) -> int:\n\n        m, n  = len(grid)+2, len(grid[0])\n        grid =[[inf]*n]+grid+[[inf]*n]\n       \n        for j in range(1,n):\n            found = False\n            for i in range(1, m-1):\n\n                if grid[i][j] <= min(grid[i-1][j-1],\n                                     grid[i  ][j-1],\n                                     grid[i+1][j-1]): grid[i][j] = inf\n                \n                else: found = True\n       \n            if not found: break\n            \n        else: return n-1\n\n        return j-1\n```\n[https://leetcode.com/problems/maximum-number-of-moves-in-a-grid/submissions/1437417433/](https://leetcode.com/problems/maximum-number-of-moves-in-a-grid/submissions/1437417433/)\n\nI could be wrong, but I think that time complexity is *O*(*MN*) and space complexity is *O*(*MN*), in which *M*, *N* ~ `m`, `n`.\n
['Python3']