✅ [Python/C++/Java/Rust] it's all just a simulation (with detailed comments)
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs a simulation approach to move balls down the box. Time complexity is linear (in each 
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs a simulation approach to move balls down the box. Time complexity is linear (in each dimension): **O(m\\*n)**. Space complexity is linear: **O(n)**\n\n**Comment.** The key trick of this simulation is the smart use of each cell\'s value, i.e., (`+1`) or  (`-1`), that provides an increment for\n* the position of the cell to compare with;\n* the position of the cell in the next row to move to.\n\n**Python.**\n```\nclass Solution:\n    def findBall(self, grid: List[List[int]]) -> List[int]:\n\n        m, n = len(grid), len(grid[0])\n        \n        # [1] function that simulates m steps\n        def move_ball(j):\n            for i in range(m):\n                k = j + grid[i][j]\n                if not (0 <= k < n) or (grid[i][k] != grid[i][j]):\n                    return -1\n                j = k\n            return j\n        \n        # [2] move n balls from the top to the bottom\n        return [move_ball(j) for j in range(n)]\n```\n\n<iframe src="https://leetcode.com/playground/oGc9ytmr/shared" frameBorder="0" width="800" height="520"></iframe>
[]