🔥🔥  CPP DFS Matrix ✔✔💯
\nclass Solution {\npublic:\n    // if the value of (i,j) -> 1 (means we are moving to the right direc) , so (i,j+1) value must be similar(1) => then move furth
```\nclass Solution {\npublic:\n    // if the value of (i,j) -> 1 (means we are moving to the right direc) , so (i,j+1) value must be similar(1) => then move further in right direc(i+1,j+1)\n    \n     // if the value of (i,j) -> -1 (means we are moving to the left direc) , so (i,j-1) value must be similar(-1) => then move further in left direc(i+1,j-1)\n    \n    // and in btw if we reach the last col we got our answer ...\n    // O.W. return -1\n    \n    int solve(int i, int j, int m, int n,vector<vector<int>>& grid)\n    {\n        if(i == m)           // if we reach the last row(i.e. -> m) => return the current col \n            return j;        \n        \n        if(grid[i][j] == 1 && j+1 < n && grid[i][j] == grid[i][j+1])  \n                                                    // moving towards the right direction \n            return solve(i+1,j+1,m,n,grid);\n        \n        else if(grid[i][j] == -1 && j-1 >= 0 && grid[i][j] == grid[i][j-1])  // moving towards the left direction \n            return solve(i+1,j-1,m,n,grid);\n        \n        return -1;\n    }\n    \n    vector<int> findBall(vector<vector<int>>& grid) \n    {\n        int m = grid.size();\n        int n = grid[0].size();\n        \n        vector<int > res(n,0);\n        \n        for(int j=0; j<n; j++)\n        {\n            res[j] = solve(0,j,m,n,grid);\n        }\n        \n        return res;\n    }\n};\n```
['Depth-First Search', 'Matrix', 'C++']