[C++] | DFS | TC : O(N*M) | SC : O(M)
\nclass Solution {\npublic:\n    \n    int dfs(vector<vector<int>>& grid,int i,int j,int row,int col){\n            \n        if(grid[i][j]==1){\n            if
```\nclass Solution {\npublic:\n    \n    int dfs(vector<vector<int>>& grid,int i,int j,int row,int col){\n            \n        if(grid[i][j]==1){\n            if(j+1 == col || grid[i][j+1]==-1) return -1;\n            \n            if(i+1<row && j+1<col) return dfs(grid,i+1,j+1,row,col);\n        }\n        \n        if(grid[i][j]==-1){\n            if(j == 0  || grid[i][j-1]==1) return -1;\n            \n            if(i+1<row && j>0) return dfs(grid,i+1,j-1,row,col);\n        }\n        \n        return grid[i][j]==1?j+1:j-1;\n        \n        \n    }\n    \n    vector<int> findBall(vector<vector<int>>& grid) {\n        \n        \n        int row=grid.size();\n        int col=grid[0].size();\n        \n        vector<int> ans(col,-1);\n        \n        for(int i=0;i<col;i++){\n            ans[i]=dfs(grid,0,i,row,col);\n        }\n        \n        return ans;\n        \n    }\n};\n```
['Depth-First Search', 'Recursion', 'C', 'C++']