JavaScript Solution - Greedy Approach
There are fourth key observations that help me solve this problem.\n\nFirst observation is that we would want the least # of negative signs as possible in the m
There are fourth key observations that help me solve this problem.\n\nFirst observation is that we would want the least # of negative signs as possible in the matrix. In other words, we want to cancel out as many pairs of negative numbers as possible by multiplying them by -1.\n\nSecond observation is that we want the negative signs to be on the smallest absolute numbers as possible. \n\nThird observation is that when you have 1 negative and 1 positive adjacent numbers and we perform the -1 multplication on them, it is like moving the negative signs around. Imagine the operation as a way to herd all the negative signs into one area where they will be paired up and canceled out by multiplying them with -1.\n\nThe final observation is that if there is an odd number of negative signs in the matrix, we should have 1 negative sign left. If there is an even number of negative signs in the matrix, then we should have 0 negative sign left.\n\nIf we do have a negative sign, we would want to assign it to the smallest **absolute** valued number in the matrix. I hope this made sense!\n\n\n```\nvar maxMatrixSum = function(matrix) {\n    const MAX= Number.MAX_SAFE_INTEGER;\n    \n    const m = matrix.length;\n    const n = matrix[0].length;\n    \n    let negs = 0;\n    \n    let totAbsSum = 0;\n    let minAbsNum = MAX;\n    \n    for (let i = 0; i < n; ++i) {\n        for (let j = 0; j < n; ++j) {\n            if (matrix[i][j] < 0) ++negs;\n            \n            totAbsSum += Math.abs(matrix[i][j]);\n            minAbsNum = Math.min(minAbsNum, Math.abs(matrix[i][j]));\n        }\n    }\n    \n    if (negs % 2 === 1) totAbsSum -= (2 * minAbsNum);\n    \n\treturn totAbsSum;\n};\n```\n
['Greedy', 'JavaScript']