✅Easy and Simple Solution ✅Clean Code
Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\nFoll
***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**\n\n# Complexity\n- Time complexity:\nO( N * M)\n\n- Space complexity:\nO(N * M)\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(vector<vector<int>>& grid, int currI , int currJ , int n , int m,vector<vector<int>>&dp){\n       if(currI >= n || currJ >= m) return 0 ;\n       \n       if(dp[currI][currJ] !=-1) return dp[currI][currJ];\n       \n        \n       int maxi1 = INT_MIN;\n       int maxi2 = INT_MIN;\n\n        if(currI + 1 < n) maxi1 = grid[currI+1][currJ] - grid[currI][currJ] + solve(grid,currI+1,currJ,n,m,dp);\n      if(currJ + 1 < m)   maxi2 = grid[currI][currJ+1] - grid[currI][currJ] + solve(grid,currI,currJ+1 , n, m,dp);\n\n       return dp[currI][currJ] = max(0,max(maxi1,maxi2));\n\n        \n    }\n    int maxScore(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        int ans = INT_MIN;\n        int ans2 = INT_MIN;\n        vector<vector<int>>dp(n,vector<int>(m,-1));\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n               \n                \n                ans = max(ans, solve(grid,i,j,n,m,dp));\n                if(i+1 < n) ans2 = max(ans2,grid[i+1][j] - grid[i][j]);\n                if(j+1 < m) ans2 = max(ans2,grid[i][j+1] - grid[i][j]);\n               \n            }\n        }\n\n        return ans == 0 ? ans2 : ans;\n    }\n};\n```\n***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**
['Array', 'Dynamic Programming', 'Matrix', 'C++']