JAVA | Simple DFS solution | 100% Runtime
Logic: \nIf the current value(i,j) is 1 then the next value in the column(i,j+1) should also be 1. \nThen, check for next row next col (i+1,j+1)\n\nIf the curre
Logic: \nIf the current value(i,j) is 1 then the next value in the column(i,j+1) should also be 1. \nThen, check for next row next col (i+1,j+1)\n\nIf the current value(i,j) is -1 then the prev value of the column(i,j-1) should also be -1. \nThen, check for next row prev col(i+1,j-1)\n\nIf any of the condition fail or goes out of bounds that ball won\'t reach the end.\n\n```\nclass Solution {\n    public int dfs(int[][] grid, int i, int j){\n        if(i==grid.length)\n            return j;\n        \n        if(j<0 || j>=grid[0].length)\n            return -1;\n        \n        if(grid[i][j]==1 && j+1<grid[0].length && grid[i][j+1]==1)\n            return dfs(grid,i+1,j+1);\n        \n        else if(grid[i][j]==-1 && j-1>=0 && grid[i][j-1]==-1)\n            return dfs(grid,i+1,j-1);\n         \n        return -1;\n    }\n    public int[] findBall(int[][] grid) {\n        int m = grid[0].length;\n        int[] ar = new int[m];\n        \n        for(int j=0;j<m;j++)\n            ar[j]=dfs(grid,0,j);\n        \n        return ar;\n    }\n}\n```
['Depth-First Search', 'Java']