Simple Iterative Solution | O(N * M) | C++
\nclass Solution {\npublic:\n    vector<int> findBall(vector<vector<int>>& grid) {\n        int n = grid.size(), m = grid[0].size();\n        vector<int> ans(m)
```\nclass Solution {\npublic:\n    vector<int> findBall(vector<vector<int>>& grid) {\n        int n = grid.size(), m = grid[0].size();\n        vector<int> ans(m);\n\n        for(int ball=0; ball<m; ball++) {\n            int i = 0, j = ball, f = 0;\n            while(i < n) {\n                if(grid[i][j] == 1) {\n                    if(j == m - 1 || grid[i][j + 1] == -1) {f = 1; break;}\n                    i++; j++;\n                }\n                else {\n                    if(j == 0 || grid[i][j - 1] == 1) {f = 1; break;}\n                    i++; j--;\n                }\n            }\n            ans[ball] = f ? -1 : j;\n        }\n        return ans;\n    }\n};\n```
['C++']