Python | Bottom Up DP Approach
\nclass Solution:\n    def findBall(self, grid: List[List[int]]) -> List[int]:\n        ROWS, COLS = len(grid), len(grid[0])\n        dp = [[i for i in range(CO
```\nclass Solution:\n    def findBall(self, grid: List[List[int]]) -> List[int]:\n        ROWS, COLS = len(grid), len(grid[0])\n        dp = [[i for i in range(COLS)] for _ in range(ROWS + 1)]\n        \n        for r in range(ROWS - 1, -1, -1):\n            for c in range(COLS):\n                nc = c + grid[r][c]\n                if nc < 0 or nc == COLS or grid[r][nc] != grid[r][c]:\n                    dp[r][c] = -1\n                else:\n                    dp[r][c] = dp[r + 1][nc]\n        \n        return dp[0]\n        \n        # TIME: O(M*N)\n        # SPACE: O(M*N)\n```
['Dynamic Programming', 'Python']