C++ Simple Solution | Track previous minimum.
Intuition\nFind the minimum element from indices (0,0) to (i, j) where index (i, j)is not included. Then, take the difference of current cell with the current m
# Intuition\nFind the minimum element from indices (0,0) to (i, j) where index (i, j)is not included. Then, take the difference of current cell with the current minimum value.\n    i.e. ans = max(ans, grid[i][j] - prev_min[i][j]);\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity: \nO(m*n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        int m = grid.size(), n = grid[0].size();\n        int ans = INT_MIN;\n        \n        // prev_min[i][j] contains the minimum of all elements from indices (0,0) to { (i, j-1), (i-1, j) }\n        vector<vector<int>> prev_min(m, vector<int>(n, INT_MAX)); \n        \n        for(int i=0; i<m; i++){\n            for(int j=0; j<n; j++){\n                if(i==0 && j==0) continue;\n                if(i>0){\n                    prev_min[i][j] = min(prev_min[i-1][j], grid[i-1][j]);\n                }\n                if(j>0){\n                    prev_min[i][j] = min(prev_min[i][j], min(prev_min[i][j-1], grid[i][j-1]) );\n                }\n                ans = max(ans, grid[i][j] - prev_min[i][j]);\n            }\n        }\n        return ans;\n        \n        \n    }\n};\n```
['C++']