DFS | Easy C++ Solution
Code\n\nclass Solution {\npublic:\n\n    void dfs(vector<vector<int>>& grid , int row , int col , int r , int c , vector<int> &ans , int column){\n        if(r=
# Code\n```\nclass Solution {\npublic:\n\n    void dfs(vector<vector<int>>& grid , int row , int col , int r , int c , vector<int> &ans , int column){\n        if(r==row){\n            if(c<col && c>=0 ){\n                ans[column]=c;\n            }\n            return ;\n        }\n        int x = grid[r][c];\n        if(x==-1){\n            if(c-1 >=0){\n                if(grid[r][c-1]==-1){\n                    dfs(grid , row , col , r+1 , c-1 , ans , column);\n                }\n            }\n        }\n        else{\n            if(c+1 < col){\n                if(grid[r][c+1]==1){\n                    dfs(grid , row , col , r+1 , c+1 , ans , column);\n                }\n            }\n        }\n    }\n\n    vector<int> findBall(vector<vector<int>>& grid) {\n        int row = grid.size();\n        int col = grid[0].size();\n        vector<int> ans(col , -1);\n        for(int i=0 ; i<col ; i++){\n            dfs(grid , row , col , 0 , i , ans , i );\n        }\n        return ans;\n    }\n};\n```
['C++']