C++ || Explained the intuition || Easy to understand
Just think in a recursive way\n\n#Forget about the final target\n#Make smaller targets for each cell\n#If ball is in any cell in the grid then we only have to s
Just think in a recursive way\n\n#Forget about the final target\n#Make smaller targets for each cell\n#If ball is in any cell in the grid then we only have to solve a **SUBPROBLEM**\n\n**SUBPROBLEM**=>\n**==========**\n#Smaller target for ball is **to reach the next row**\n#We just want to somehow figure out solution to reach the next row for any current cell\n#For any cell we have two scenarios\n\t\t\t1. If board in currCell [grid[i][j]] is "RIGHT" :\n\t\t\t       =>We can move to next row if board in the rightCell of currCell [grid[i][j + 1]] is also "RIGHT" \n           2.If board in currCell [grid[i][j]] is "LEFT" :\n\t\t\t    =>We can move to next row if board in the leftCell of currCell [grid[i][j - 1]] is also "LEFT"\n\t  \n#If we **cannot reach the next row** after evaluating the above conditions\n    =>ANSWER TO SUBPROBLEM ==> -1 :(\n\t\n#If ball is **able to get into the next row**\n    =>Now we are closer to out goal to reach bottom row\n    =>We are in some cell of nextRow depending on above scenarios\n    =>Now it\'s again a same "SUBPROBLEM" [RECURSION AT IT\'S BEST :)] but with reduced size\n    =>ANSWER TO CURRENT SUBPROBLEM => Answer of next subproblem (for a grid cell of next row) \n#Answer to any subproblem will be the column by which it get\'s into the next row\n\n\n\n**#If you can\'t find a solution to the bigger problem \n#Just figure out what all you can do at current steps\n#The next step will be ultimately solved using "RECURSION" :) [LIFE PHILOSOPHY]**\n\n\n```\nclass Solution {\npublic:\n    vector<int> findBall(vector<vector<int>>& grid) \n    {\n        int m = grid.size(), n = grid[0].size();\n        vector<vector<int>>dp(m + 1, vector<int>(n, -1));\n        for (int j = 0; j < n; j++) dp[m][j] = j; //Initializing the answer to the bottom case subproblem\n        //===================================================\n        for (int i = m - 1; i >= 0; i--) //Move from bottom to top,                        \n        {                               //as subproblems of next row should be solved before current row\n            for (int j = 0; j < n; j++)\n            {\n                if (grid[i][j] == 1) //if board is right\n                {\n                    bool isRightCellRight = (j + 1 == n)? false : (grid[i][j + 1] == 1);\n                    if (isRightCellRight) dp[i][j] = dp[i + 1][j + 1]; \n                    //if we can reach next row, take the answer from the next row subproblem\n                }\n                else if (grid[i][j] == -1) //if board is left\n                {\n                    bool isLeftCellLeft = (j - 1 < 0)? false : (grid[i][j - 1] == -1);\n                    if (isLeftCellLeft) dp[i][j] = dp[i + 1][j - 1];\n                }\n            }\n        }\n        //=============================================================\n        return dp[0];\n        \n    }\n};\n```
['Dynamic Programming', 'Recursion', 'C', 'C++']