Short, simple, efficient, easy to understand Python solution.
Intuition\n Describe your first thoughts on how to solve this problem. \nUse the values for the diagonals to figure out where the ball moves after each row. Val
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse the values for the diagonals to figure out where the ball moves after each row. Value of 1 means ball moves over 1 column. Value of -1 means the ball moves backward 1 column.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMaintain an array for the index location of each ball and iterate over each row of the grid and update the location of each ball. Use the value in the grid to determine which direction the ball falls in. \n\nAdditionally check for a "hole" where the ball gets stuck between two diagonals or between a diagonal and a wall. Do this by using the direction of the diagonal in the cell the ball is in to figure out which cell is the neighbor that might trap the ball. If the values in these two cells sums to zero, it means the ball is trapped and you can set the position of that ball to -1. \n\nContinue this process all the way through the last row. \n\n[Super Quick Video Explanation <3 min](https://youtu.be/-RDPsvkJX2A)\nhttps://youtu.be/-RDPsvkJX2A \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(MN)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(MN)$$ Grid of size MN plus array of size N\n# Code\n```\nclass Solution(object):\n    # determine whether the ball has fallen into a hole\n    def nextPosition(self, row, j, max):\n        if (j == -1): \n            return -1 # stuck in hold\n        else:\n            direction = row[j] # current direction ball is falling\n            neighborpos = j + direction # neighbor in the direction ball is falling\n            # if at wall set neighbor to opposite of current direction\n            neighborval = -direction if (neighborpos < 0 or neighborpos > max) else row[neighborpos]\n            if (direction + neighborval == 0): # stuck at wall or in hole\n                return -1\n            else:\n                return neighborpos\n        \n\n    def findBall(self, grid):\n        rows = len(grid)\n        balls = len(grid[0])\n        positions = [i for i in range(balls)]\n        for i in range(rows):\n            positions = [(self.nextPosition(grid[i], j, balls-1)) for j in positions]\n        return positions\n```
['Python']