JAVA | Grid iteration
Please Upvote :D\n\nclass Solution {\n    public int[] findBall(int[][] grid) {\n        int m = grid.length, n = grid[0].length;\n        int[] ans = new int[n
### **Please Upvote** :D\n```\nclass Solution {\n    public int[] findBall(int[][] grid) {\n        int m = grid.length, n = grid[0].length;\n        int[] ans = new int[n];\n\n        for (int col = 0; col < n; col++) {\n            int curr = col;\n\n            for (int row = 0; row < m; row++) {\n                int next = curr + grid[row][curr];\n\n                if (next < 0 || next >= n || grid[row][curr] != grid[row][next]) {\n                    curr = -1;\n                    break;\n                }\n\n                curr = next;\n            }\n\n            ans[col] = curr;\n        }\n\n        return ans;\n    }\n}\n\n// TC: O(m * n), SC: O(n)\n```
['Java']