Python 3 | Easy solution | Clean code | No extra space
Intuition\n Describe your first thoughts on how to solve this problem. \nThe big observation for solving this problem is to realise that there is  always at mos
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe big observation for solving this problem is to realise that **there is  always at most one negative number**. So if there is an even number of negative numbers we can flip all of them and if there an odd number them we can always flip all of them except of one. \n \n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count how many negative there are\n2. If there is an evem number of negative numbers, we return sum of absolute values of all elements\n3. If there is an odd number of negative numbers, wer return sum of absolute values of all elements and subtract the minimum absolute value twice (cause we want to make that number negative)\n\n# Complexity\n- Time complexity: $$O(n * m$$)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def maxMatrixSum(self, matrix: List[List[int]]) -> int:\n        abs_min = float(\'inf\') # minimum absolulte value in matrix\n        cnt = 0 # counter of negative number\n        abs_sum = 0 # sum of absolute values\n\n        for i in range(len(matrix)):\n            for j in range(len(matrix[0])):\n                if matrix[i][j] < 0:\n                    cnt += 1\n                \n                abs_min = min(abs(matrix[i][j]), abs_min) #\n                abs_sum += abs(matrix[i][j])\n            \n        return abs_sum if cnt % 2 == 0 else abs_sum - abs_min * 2\n\n```\n\nPlease upvote if it was helpful.
['Matrix', 'Python', 'Python3']