Count Negative Numbers Only
Intuition:\n1. Convert all matrix elements to their absolute values to maximize the sum.\n2. Track the count of negative numbers to determine if their product w
**Intuition:**\n1. Convert all matrix elements to their absolute values to maximize the sum.\n2. Track the count of negative numbers to determine if their product will affect the result:\n3. Even negatives: All negatives can effectively be "flipped" to positives.\n4. Odd negatives: One smallest absolute value must remain negative.\n5. Deduct twice the smallest absolute value when the negatives are odd to minimize the impact.\n\n**Complexity**:\nTime Complexity:O(n^2)\nSpace Complexity: O(1), no extra space is used beyond variables.\n# Code\n```python3 []\nclass Solution:\n    def maxMatrixSum(self, matrix: List[List[int]]) -> int:\n        n = len(matrix)\n        def absSmall(matr):\n            small = abs(matr[0][0])\n            for i in range(n):\n                for j in range(n):\n                    small = min(small, abs(matr[i][j]))\n            return small\n        \n        countNegative = 0\n        totalSum = 0\n        for i in range(n):\n            for j in range(n):\n                if matrix[i][j] <0:\n                    countNegative +=1\n                totalSum += abs(matrix[i][j])\n        small = absSmall(matrix)\n        if countNegative %2 == 0:\n            return totalSum\n        else:\n            return totalSum - 2*small \n\n```\n```java []\nclass Solution {\n    public int maxMatrixSum(int[][] matrix) {\n        int n = matrix.length;\n        \n        int absSmall(int[][] matr) {\n            int small = Math.abs(matr[0][0]);\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    small = Math.min(small, Math.abs(matr[i][j]));\n                }\n            }\n            return small;\n        }\n        \n        int countNegative = 0;\n        int totalSum = 0;\n        \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (matrix[i][j] < 0) {\n                    countNegative++;\n                }\n                totalSum += Math.abs(matrix[i][j]);\n            }\n        }\n        \n        int small = absSmall(matrix);\n        if (countNegative % 2 == 0) {\n            return totalSum;\n        } else {\n            return totalSum - 2 * small;\n        }\n    }\n}\n```
['Array', 'Greedy', 'Matrix', 'Java', 'Python3']