C++ soln || using DP
\n\n# Code\n\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        \n        int n = grid.size(), m = grid[0].size();\n        vect
\n\n# Code\n```\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        \n        int n = grid.size(), m = grid[0].size();\n        vector<vector<int>>dp(n,vector<int>(m,INT_MIN));\n         int res = INT_MIN;\n        \n        dp[0][0] = 0;\n        \n        int mi = grid[0][0];\n        for(int j = 1; j < m; j++)\n        {\n            dp[0][j] = max(dp[0][j], grid[0][j] - mi);\n            mi = min(grid[0][j],mi);\n            res = max(res, dp[0][j]);\n        }\n        \n        mi = grid[0][0];\n        for(int i = 1; i < n; i++)\n        {\n            dp[i][0]= max(dp[i][0], grid[i][0]-mi);\n            mi = min(mi,grid[i][0]);\n            res = max(res, dp[i][0]);\n        }\n        \n       \n        \n        for(int i = 1; i < n; i++)\n        {\n            for(int j = 1; j < m; j++)\n            {\n                int d1 = grid[i][j] - grid[i][j-1];\n                int d2 = grid[i][j] - grid[i-1][j];\n                \n                dp[i][j] = max(dp[i][j], max(d1,d2));\n                dp[i][j] = max(dp[i][j], max(d1+dp[i][j-1], d2+dp[i-1][j] ));\n                \n                res = max(res,dp[i][j]);\n            }\n        }\n        \n        return res;\n    }\n};\n```
['Dynamic Programming', 'Matrix', 'C++']