100% faster in java
Intuition\nMy first intuition was to do it with bruitforce and I was able to solve 62/64 test cases using that. Then I came across the iterative approach witht 
# Intuition\nMy first intuition was to do it with bruitforce and I was able to solve 62/64 test cases using that. Then I came across the iterative approach witht he intent to inculcate it in my brute force approach. But while solving these, I did have a context that questions can usually be solved using dfs. Using the corner I used in iterative solution, I formed base cases for dfs and ran it through.\n\n# Approach\nThe idea is to create a next value of J, put it through all the corner case constraints, and if it passes those, move it to the next row it can go into. we dont need to create and return the new j for base case i == grid.length because it being equal to grid.length means it is already out of matric and the new J was sent to this call.\n\n\n# Code\n```\nclass Solution {\n    public int[] findBall(int[][] grid) {\n\n        int[] result = new int[grid[0].length];\n\n        for(int i=0; i<result.length; i++){\n            result[i] = dfs(0,i,grid);\n        }\n        return result;\n    }\n\n    private int dfs(int i, int j, int[][] grid){\n\n        if(i == grid.length){\n            return j;\n        }\n\n        int newj = j + grid[i][j];\n\n        if(newj<0 || newj>=grid[0].length || grid[i][j] != grid[i][newj]){\n            return -1;\n        }\n\n        \n\n       \n        return dfs(i+1,newj,grid);   \n       \n\n    }\n}\n```
['Java']