Kotlin: DFS
\n# Code\n\nclass Solution {\n    fun findBall(grid: Array<IntArray>): IntArray {\n        val ans = IntArray(grid[0].size) { 0 }\n        \n        fun dfs(i: 
\n# Code\n```\nclass Solution {\n    fun findBall(grid: Array<IntArray>): IntArray {\n        val ans = IntArray(grid[0].size) { 0 }\n        \n        fun dfs(i: Int, j: Int): Int {\n            if (i == grid.size) return j\n            val J = j + grid[i][j]\n            if (J !in grid[0].indices || grid[i][j] != grid[i][J]) return -1\n            return dfs(i + 1, J)\n        }\n\n        for (i in 0 until grid[0].size) ans[i] = dfs(0, i)\n\n        return ans\n    }\n}\n\n```
['Depth-First Search', 'Kotlin']