C++ || NO DP || NO RECURSION || NEXT GREATER ELEMENT MATRIX || Beginner Friendly
First read the question 2-3 times(iff necessary) to get the basic understanding of question.\n\nHint: try to look different ways to get the answer ( I personall
## **First read the question 2-3 times(iff necessary) to get the basic understanding of question.**\n\n**Hint:** try to look different ways to get the answer ( I personally suggest using pen and paper )\n\n\n\n**Explaination:** lets say you are at position (0,1) with value "5" and you want to find the max difference by traversing right and down only (not necessarily to adjacent element), just look for maximum element in submatrix of (0,1) excluding element at (0,1) lets say you find max element at (2,2) with value "14" now conclude that no matter what path you choose to reach (2,2) the sum of difference always gonna be (14-5)=9. then just use next greater elemnt technique to precompute the max element of every submatrix and find the answer !\n\n![image](https://assets.leetcode.com/users/images/20b28089-41b6-4562-825f-a503ebe7c068_1715881495.7472982.png)\n\nCode: \n```\n#pragma GCC optimize("fast")\nstatic auto _ = [] () {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);return 0;}();\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        int mr[n][m],mc[n][m];\n        for(int i=0;i<n;i++){\n            int ma=0;\n            for(int j=m-1;j>=0;j--){\n                ma=max(grid[i][j],ma);\n                mr[i][j]=ma;\n            }\n        }\n        for(int j=0;j<m;j++){\n            int ma=0;\n            for(int i=n-1;i>=0;i--){\n                ma=max(mr[i][j],ma);\n                mc[i][j]=ma;\n            }\n        }\n        int ans=INT_MIN;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int a=-1,b=-1;\n                if(i+1<n){\n                    a=mc[i+1][j];\n                }\n                if(j+1<m){\n                    b=mc[i][j+1];\n                }\n                if(a>-1 || b>-1){\n                    ans=max(ans,max(a,b)-grid[i][j]);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```\n\n\n\nAn Upvote will be appreciated \uD83C\uDF89 !!!\nCheers\uD83E\uDD42
['C', 'Matrix']