Javascript | Recursive | Beats 96% solutions
\nvar findBall = function(grid) {\n    let m = grid.length;\n    const n = grid[0].length;\n    \n    const answer = [...Array(n)].fill(-1);\n    \n    const mo
```\nvar findBall = function(grid) {\n    let m = grid.length;\n    const n = grid[0].length;\n    \n    const answer = [...Array(n)].fill(-1);\n    \n    const moveBall = (index, row, col) => {\n        if (row === m) {\n            answer[index] = col;\n            return true;\n        }\n        \n        if (row >= m || col < 0 || col >= n) {\n            return false;\n        }\n        \n        const dir = grid[row][col];\n        const next = [];\n        \n        switch(dir) {\n            case 1: {\n                const next = grid[row]?.[col + 1];\n                if (next === 1) {\n                    moveBall(index, row + 1, col + 1);\n                }\n                break;\n            }\n                \n            case -1: {\n                const next = grid[row]?.[col - 1];\n                if (next === -1) {\n                    moveBall(index, row + 1, col - 1);\n                }\n                break;\n            }\n        }\n    }\n    \n    for(let i = 0; i < n; i++) {\n        moveBall(i, 0, i);\n    }\n    \n    return answer;\n};\n```
['Recursion', 'JavaScript']