EASY PYTHON SOLUTON || O(mxn) || Comments
Time Complexity  - O(mxn)\nRuntime - 202ms , \nMemory  - 14.6MB\n\nConcept:\nIf a ball get out of the box i.e., row==len(grid), we just return the column. if th
Time Complexity  - O(mxn)\nRuntime - 202ms , \nMemory  - 14.6MB\n\nConcept:\nIf a ball get out of the box i.e., row==len(grid), we just return the column. if the new column is already out of the box or the next cell doesn\'t equal to grid[row][col] the ball will get stuck and we just return -1\n\n*(Upvote if it was helpful)*\n\n```\nclass Solution:\ndef findBall(self, grid: List[List[int]]) -> List[int]:\nm,n = len(grid),len(grid[0])\ndef check(row,col):\n### If a ball get out of the box, return col\nif row==m:\nreturn col\n\n### note that since grid contains 1 and -1 representing to right and to left, \n### we can just add the grid[row][col] to current collumn to get the new column\nnew_col = col+grid[row][col]\n\n### if the new column is already out of the box \n### or the neighbor cell doesn\'t equal to grid[row][col] \n### the ball will get stuck and we just return -1\nif new_col==n or new_col==-1 or grid[row][new_col]!=grid[row][col]:\nreturn -1\nelse:\nreturn check(row+1,new_col)\nres = []\nfor i in range(n):\nres.append(check(0,i))\nreturn res\n```\n```
['Python', 'Python3']