[Python] Clear Solution with Video Explanation
Video with clear visualization and explanation:\nhttps://youtu.be/HeGDdUvNDNc\n\nIntuition: Straight Implementation\n\n\nCode\nInspired by https://leetcode.com/
Video with clear visualization and explanation:\nhttps://youtu.be/HeGDdUvNDNc\n\nIntuition: Straight Implementation\n\n\n**Code**\nInspired by https://leetcode.com/problems/where-will-the-ball-fall/discuss/988156/PythonC%2B%2B-let-the-balls-fall-row-by-row-O(MN)\n\n```\nclass Solution:\n    def findBall(self, grid: List[List[int]]) -> List[int]:\n        n_r, n_c = len(grid), len(grid[0])\n        answer = list(range(n_c))\n        \n        for r in range(n_r):\n            for i in range(n_c):\n                c = answer[i]\n                if c == -1: continue\n                c_nxt = c+grid[r][c]\n                if c_nxt < 0 or c_nxt >= n_c or grid[r][c_nxt] == -grid[r][c]:\n                    answer[i] = -1\n                    continue\n                answer[i] += grid[r][c]\n        \n        return answer\n```\n\nTime: O(m*n) / Space: O(1)\n\n\nFeel free to subscribe to my channel. More LeetCoding videos coming up!
['Python']