Very Simple | Greedy | Clean Code
Intuition\n Describe your first thoughts on how to solve this problem. \nThis question is more of cp based rather of DSA.\nWe will count the number of elements 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question is more of cp based rather of DSA.\nWe will count the number of elements in the matrix which are negative and also make a`sum`variable having sum of absolute values of elements of`matrix`and we will also keep track of minimum absoulte value of elements in the`matrix`.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf the count of negative numbers is even then we can somehow convert all the negative numbers into positive numbers so we will return the `sum` as our answer.\nElse if the`count`is odd then one element will be left negative in the`matrix`so we will want that element to be the minimum element so we will return`sum-2*mini`because we added positive value of that element so we will subtract it once to exclude it and again subtract it as now it has negative value.\n# Complexity\n- Time complexity: O(n*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long maxMatrixSum(vector<vector<int>>& matrix) {\n        long long sum=0;\n        int n=matrix.size(),count=0,mini=INT_MAX;\n        for(int i=0; i<n; i++){\n            for(int j=0; j<n; j++){\n                sum+=abs(matrix[i][j]);\n                mini=min(mini,abs(matrix[i][j]));\n                if(matrix[i][j]<0) \n                    count++;\n            }\n        }\n        if(count%2==0) return sum;\n        else return sum-2*mini;\n    }\n};\n```
['Array', 'Greedy', 'Matrix', 'C++']