✅ Explained Python Solution | BFS
Time:O(NM)\nKeep an array (output) to store the current position of the balls.\nCases:\n1.  If the current position (pos) of ball is -1 in the output array, the
**Time:O(NM)**\nKeep an array (output) to store the current position of the balls.\n**Cases:**\n1.  If the current position (pos) of ball is -1 in the output array, then it means ball is already stuck.\n2.  if the pos == 0 and grid[row][pos] == -1 it means we can\'t move further so update the output array to -1.\n3.  Similarly if the pos == N and grid[row][pos] == 1 it means we can\'t move further so update the output array to -1.\n4.  Else update the output[pos] by comparing grid[row][pos] by the adjacent column and if the sum of both column values != 0 then update the pos\n5.  Else set output[pos] = -1\n\n```\nclass Solution:\n    def findBall(self, grid: List[List[int]]) -> List[int]:\n        N = len(grid[0])-1\n        output = list(range(N+1))\n        for i in range(len(grid)):\n            for index,pos in enumerate(output):\n                if pos == -1 :\n                    continue\n                if ((pos == 0 and grid[i][pos]==-1) or\n                    (pos == N and grid[i][pos] == 1)):\n                    output[index] = -1\n                elif grid[i][pos] == 1 and grid[i][pos]+grid[i][pos+1]!=0:\n                    output[index]+=1\n                elif grid[i][pos] == -1 and grid[i][pos]+grid[i][pos-1] !=0:\n                    output[index]-=1\n                else:\n                    output[index] = -1\n        return output\n                \n```
['Breadth-First Search', 'Python']