Easy to Understand || Dynamic Programming || Two - Approaches || C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n   int solve(int i, int j, int &mx, vector<vector<int>>& grid, vector<vector<int>>& dp) {\n    int n = grid.size();    // Number of rows in the grid\n    int m = grid[0].size(); // Number of columns in the grid\n\n    // Base case: if out of bounds, return a very small number to indicate invalid path\n    if (i >= n || j >= m) return -1e8;\n\n    // Return the precomputed result if it exists in the dp table\n    if (dp[i][j] != -1) return dp[i][j];\n\n    // Recursive call to explore the path moving downward\n    int bottom = solve(i + 1, j, mx, grid, dp);\n\n    // Recursive call to explore the path moving rightward\n    int right = solve(i, j + 1, mx, grid, dp);\n\n    // Determine the maximum cell value that can be obtained from either moving downward or rightward\n    int maxi = max(bottom, right);\n\n    // Update the ans \'mx\' found so far by considering the current cell\n    mx = max(mx, maxi - grid[i][j]);\n\n    // Store and return the maximum value of the current cell \n    return dp[i][j] = max(maxi, grid[i][j]);\n}\n\n    int maxScore(vector<vector<int>>& grid) {\n        \n\n        // Approach - 01\n\n        int n = grid.size();   \n        int m = grid[0].size(); \n\n        int mx = -1e8;\n        vector<vector<int>>dp(n,vector<int>(m,-1));\n         solve(0,0,mx,grid,dp);\n         return mx;\n         \n        \n\n\n        //  Approach - 02\n\n        int ans = INT_MIN; // Initialize the maximum score to the smallest possible integer\n\n        // Iterate through each cell in the grid\n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < m; j++) {\n                int mini = INT_MAX; // Initialize mini to the largest possible integer\n\n                // Skip the top-left cell (0,0) as it has no previous cell to compare\n                if(i == 0 && j == 0) continue;\n\n                // Update mini with the minimum value from the cell directly above\n                if(i != 0) mini = min(mini, grid[i-1][j]);\n\n                // Update mini with the minimum value from the cell directly to the left\n                if(j != 0) mini = min(mini, grid[i][j-1]);\n\n                // Compute the score for the current cell and update the maximum score found so far\n                ans = max(ans, grid[i][j] - mini);\n\n                // Update the current cell value in the grid to be the minimum of itself and the mini value found\n                grid[i][j] = min(mini, grid[i][j]);\n            }\n        }\n\n        \n        // return ans;\n\n        \n    }\n};\n\n```
['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'Matrix', 'C++']