Very Simple || Memoization || DFS Solution
\nclass Solution {\n    Integer memo[][],m,n;\n    public int[] findBall(int[][] grid) {\n        m=grid.length; n=grid[0].length; memo = new Integer[m][n];\n  
```\nclass Solution {\n    Integer memo[][],m,n;\n    public int[] findBall(int[][] grid) {\n        m=grid.length; n=grid[0].length; memo = new Integer[m][n];\n        int i,ar[]=new int[n];\n        for(i=0;i<n;i++) ar[i]=go(grid,i,0);\n        return ar;\n    }\n    int go(int[][] grid, int i, int j){\n        if(j==m) return i;\n        if(memo[j][i]!=null) return memo[j][i];\n        if(grid[j][i]==1){\n            if((i+1)==n || grid[j][i+1]==-1) return -1;\n            else return memo[j][i]=go(grid,i+1,j+1);\n        }else{\n            if((i-1)==-1 || grid[j][i-1]==1) return -1;\n            else return memo[j][i]=go(grid,i-1,j+1);\n        }\n    }\n}\n```
['Dynamic Programming', 'Depth-First Search', 'Memoization', 'Java']