Python || Greedy || Easy
Intuition\nWe want to maximize the sum of matrix elements after potentially flipping signs. \n(Flipping as we\'re multiplyting with -1 -> sign change, magnitude
### Intuition\nWe want to maximize the sum of matrix elements after potentially flipping signs. \n(Flipping as we\'re multiplyting with -1 -> sign change, magnitude same) \n\nWhichever elements we choose, at the end we will have just 1 negative number if initially the number of negatives were odd. \nIf they were even, we will be left with 0 negatives.\n\nSo, in case of even negative signs, we just need the absolute sum. \n\nAnd in case of odd, we can assign that negative sign to the smallest absolute value in the array.\n\n### Approach\n1. Traverse the matrix and compute:\n   - The absolute sum of all elements.\n   - The smallest absolute value (to handle the case of odd negatives).\n   - The count of negative numbers.\n2. If the number of negatives is odd, flipping one smallest absolute value will maximize the sum.\n3. If the negatives are even, no flips are required.\n\n### Complexity\n- **Time complexity:**  \n  $$O(m \\times n)$$, where \\(m\\) and \\(n\\) are the dimensions of the matrix (traversing all elements).\n\n- **Space complexity:**  \n  $$O(1)$$, as no additional data structures are used.\n\n### Code\n```python\nclass Solution:\n    def maxMatrixSum(self, matrix: List[List[int]]) -> int:\n        smallest_num = float(\'inf\')  # Smallest absolute value\n        abs_sum = 0\n        negatives = 0\n        rows, cols = len(matrix), len(matrix[0])\n        \n        for row in range(rows):\n            for col in range(cols):\n                value = matrix[row][col]\n                abs_sum += abs(value)\n                smallest_num = min(smallest_num, abs(value))\n                if value < 0:\n                    negatives += 1\n        \n        # If odd negatives, adjust by subtracting twice the smallest absolute value\n        if negatives % 2:\n            return abs_sum - 2 * smallest_num\n        return abs_sum\n```\n\nHappy coding!\n:)\n
['Array', 'Greedy', 'Matrix', 'Python3']