✅Recursion || DP Memoization || Step by Step || C++ 🚀 || Try all ways 💯
RECURSION \uD83D\uDE80\n\nclass Solution {\nprivate:\n    int helpme(int row, int col, vector<vector<int>>& grid, int currVal)\n    {\n        int n = grid.size
RECURSION \uD83D\uDE80\n```\nclass Solution {\nprivate:\n    int helpme(int row, int col, vector<vector<int>>& grid, int currVal)\n    {\n        int n = grid.size(), m = grid[0].size();\n        if (row >= n or col >= m)   return -1e8;\n        \n        int ops1 = 0 , ops2 = 0, ops3 = 0;\n        \n        if (row - 1 >= 0 and col + 1 < m)\n        {\n            int val1 = grid[row-1][col+1];\n            if (val1 > currVal)   ops1 = 1 + helpme(row-1, col+1, grid, val1);\n        }\n        \n        if (row >= 0 and col + 1 < m)\n        {\n            int val2 = grid[row][col+1];\n            if (val2 > currVal)   ops2 = 1 + helpme(row, col+1, grid, val2);\n        }\n        \n        if (row + 1 < n and col + 1 < m)\n        {\n            int val3 = grid[row+1][col+1];\n            if (val3 > currVal)   ops3 = 1 + helpme(row+1, col+1, grid, val3);\n        }\n        \n        return max(ops1, max(ops2, ops3));\n    }\n    \npublic:\n    int maxMoves(vector<vector<int>>& grid) \n    {\n        int ans = 0;\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        for (int i=0;i<n;i++)\n        {\n            int currVal = grid[i][0];\n            int count = helpme(i, 0, grid, currVal);\n            ans = max(ans, count);\n        }\n        \n        return ans;\n    }\n};\n```\n\nDP (Memoization) \uD83D\uDE80\n```\nclass Solution {\nprivate:\n    int helpme(int row, int col, vector<vector<int>>& grid, int currVal, vector<vector<int>> &dp)\n    {\n        int n = grid.size(), m = grid[0].size();\n        if (row >= n or col >= m)   return -1e8;\n        if (dp[row][col] != -1)   return dp[row][col];\n        \n        int ops1 = 0 , ops2 = 0, ops3 = 0;\n        \n        if (row - 1 >= 0 and col + 1 < m)\n        {\n            int val1 = grid[row-1][col+1];\n            if (val1 > currVal)   ops1 = 1 + helpme(row-1, col+1, grid, val1, dp);\n        }\n        \n        if (row >= 0 and col + 1 < m)\n        {\n            int val2 = grid[row][col+1];\n            if (val2 > currVal)   ops2 = 1 + helpme(row, col+1, grid, val2, dp);\n        }\n        \n        if (row + 1 < n and col + 1 < m)\n        {\n            int val3 = grid[row+1][col+1];\n            if (val3 > currVal)   ops3 = 1 + helpme(row+1, col+1, grid, val3, dp);\n        }\n        \n        return dp[row][col] = max(ops1, max(ops2, ops3));\n    }\n    \npublic:\n    int maxMoves(vector<vector<int>>& grid) \n    {\n        int ans = 0;\n        int n = grid.size();\n        int m = grid[0].size();\n        vector<vector<int>>dp(n+1, vector<int>(m+1, -1));\n        \n        for (int i=0;i<n;i++)\n        {\n            int currVal = grid[i][0];\n            int count = helpme(i, 0, grid, currVal, dp);\n            ans = max(ans, count);\n        }\n        \n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'C++']