C++ iteration and count with explantaion
We need to just count the number of negative numbers in the given matrix, if it is even than all negative numbers can be made positive so the sum will be sum of
We need to just count the number of negative numbers in the given matrix, if it is even than all negative numbers can be made positive so the sum will be sum of absolute value of all elements.\n\nIf the count of negative numbers is odd then we\'ll have 1 negative number so add sum of absolute value of all numbers and then subtract 2*minelement  this is because we included it once in the absolute sum,\nso first we need to undo the addition of the absolute value\nthen we need to add the negative.\n\n\n\n\n```\nclass Solution {\npublic:\n    long long maxMatrixSum(vector<vector<int>>& A) {\n      long long sum = 0;\n\tlong long negative = 0;\n       long long N= A.size();\n\n\tlong long minVal = INT_MAX;\n\n\tfor (int i = 0; i < N; i++) {\n\t\tfor (int j = 0; j < N; j++) {\n\t\t\tsum += abs(A[i][j]);\n\t\t\t\n\t\t\tif (A[i][j] < 0) \n\t\t\t\tnegative++;\n\t\t\t\n            if(minVal>abs(A[i][j]))\n                minVal=abs(A[i][j]);\n\n\t\t}\n\t}\n\t\n\tif (negative % 2) \n\t\tsum -= 2 * minVal;\n\t\n\treturn sum;\n    }\n};
[]