Java beginner solution faster than 100% with fun comments.
\nclass Solution {\n    private int helper(int i, int j, int[][] grid){\n        \n        if(j<0 || j>=grid[0].length) return -1; //if stuck at the corner cond
```\nclass Solution {\n    private int helper(int i, int j, int[][] grid){\n        \n        if(j<0 || j>=grid[0].length) return -1; //if stuck at the corner condition\n        if(i == grid.length) return j; //if reached the end return the column no.\n        \n        int dir = grid[i][j]; //get direction\\\n        \n        //check if we have an opening to slide our balls in right direction\n        if(dir == 1 && j+1 < grid[0].length && grid[i][j+1] != -1){ \n            return helper(i+1,j+1,grid); //if yes slide in the ball and continue\n        }\n        \n        //check if we have an opening to slide our balls in left direction\n        if(dir == -1 && j-1 >= 0 && grid[i][j-1] != 1){\n            return helper(i+1,j-1,grid); //if yes slide in the ball and continue\n        }\n        return -1; //if we can\'t slide our balls in return -1 as the ball is stuck in the middle.\n        \n    }\n    \n    public int[] findBall(int[][] grid) {\n        int ans[] = new int[grid[0].length]; //building ans\n        for (int i = 0; i < grid[0].length;i++){ //start sliding one ball from each column.\n            ans[i] = helper(0,i,grid);\n        }\n        return ans; //return ans.\n    }\n}\n```
['Depth-First Search', 'Recursion', 'Java']