Simplest Approach
Intuition \nObserve the matrix\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1.  Calculate the absolute sum of all elements of th
# Intuition \nObserve the matrix\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1.  Calculate the absolute sum of all elements of the matrix\n2.  calculate the number of negative elements\n3.  store the minimum absolute value of the matrix\n4.  1.if number of negative elements is even then they all become positive so in this case return total_sum\n    2. if the number of negative elements is odd only one negative element left in the last so we make smallest absolute number as our last negative number to maximise our total_sum\nso in this case return total_sum-2*(smallest absolute number)\nhere 2 comes because the number is already added in total_sum\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^2)\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 total_sum=0;\n        int n=matrix.size();\n        int mini=INT_MAX;\n        int cnt_neg=0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                total_sum+=abs(matrix[i][j]);\n                mini=min(mini,abs(matrix[i][j]));\n                if(matrix[i][j]<0) cnt_neg++;\n            }\n        }\n        if(cnt_neg%2==0){\n            return total_sum;\n        }else{\n            return total_sum-2*mini;\n        }\n    }\n};\n```
['C++']