Greedy Java solution with detailed explanation
Analyze:\n1. The operation can move all negative cells together.\n2. At most 1 negative cell can left while put all negative numbers together.\n3. The last nega
Analyze:\n1. The operation can move all negative cells together.\n2. At most 1 negative cell can left while put all negative numbers together.\n3. The last negative cell can move the the global smallest cell.\n4. If the min cell value is 0, then the last negative cell will be turn to positive.\n\nSolution:\n1. sum absolute value of entire matrix\n2. tracking the number of negative cells is even or not\n3. get global min vlaue of the matrix.\n\nIf even negatives, return sum of absolute values;\nelse return (sum - 2 * min).\n\nSince sum already includes min, so we need to exclude the min cell first (sum - min), then reduce it again [(sum - min) - min].\n\n```\nclass Solution {\n    public long maxMatrixSum(int[][] matrix) {\n        boolean even = true;  //track the number of negative cells is even or not\n        int min = Integer.MAX_VALUE; //global absolute min value\n        long sum = 0;\n        \n        for (int[] row : matrix) {\n            for (int x : row) {\n                if (x < 0) {\n                    even = !even;\n                    x = -x;\n                }\n                min = Math.min(min, x);\n                sum += x;\n            }\n        }\n        return even ? sum : sum - 2 * min;\n    }\n}\n```
[]