Intution -> Observation -> Code Conversion idea || Very Easy Diagram explain
Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/zTSzxOvw_yg?si=x3agO7LMkmcMNtGM\n\n# Intuition 
# Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/zTSzxOvw_yg?si=x3agO7LMkmcMNtGM\n\n# Intuition and Approach\n> This Question is completely observation based, when you dry run some example you will be like suddenly *" Oh, that\'s what it is happening !"*\n\n![image.png](https://assets.leetcode.com/users/images/f9534df6-10a7-4036-b288-190f7b99edaf_1732427182.2516735.png)\n![image.png](https://assets.leetcode.com/users/images/47fe9c62-afe8-4a27-a4a7-e244a00c38f4_1732427203.2960062.png)\n![image.png](https://assets.leetcode.com/users/images/b8aaa166-363a-414d-9425-9e2c84c62737_1732427212.1575005.png)\n![image.png](https://assets.leetcode.com/users/images/856a6f6d-cebd-486c-865b-b2511514c64e_1732427222.9733222.png)\n![image.png](https://assets.leetcode.com/users/images/13712a54-958c-4f4c-bac2-fe57f5670087_1732427234.8120098.png)\n\n\n# Complexity\n- Time complexity: O(row x col)\n- Space complexity: O(1)\n\n# Code\n``` Codes>>> [ ]\nHope You Enjoyed the Explanation !!\n```\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n    ll maxMatrixSum(vector<vector<int>>& matrix) {\n        ll sum = 0, n = matrix.size(), cnt = 0, mini=INT_MAX;\n        for(int row=0;row<n;row++){\n            for(int col=0;col<n;col++){\n                if(matrix[row][col] < 0){\n                    cnt++;\n                }\n                mini = min((ll)abs(matrix[row][col]), mini);\n                sum += abs(matrix[row][col]);\n            }\n        }\n        \n        if(cnt&1){\n            sum -= (2*mini);\n        }\n        return sum;\n    }\n};\n```\n``` Java [ ]\nclass Solution {\n    public long maxMatrixSum(int[][] matrix) {\n        long sum = 0, mini = Long.MAX_VALUE;\n        int n = matrix.length, cnt = 0;\n        \n        for (int row = 0; row < n; row++) {\n            for (int col = 0; col < n; col++) {\n                if (matrix[row][col] < 0) {\n                    cnt++;\n                }\n                mini = Math.min(Math.abs(matrix[row][col]), mini);\n                sum += Math.abs(matrix[row][col]);\n            }\n        }\n        \n        if ((cnt & 1) == 1) {\n            sum -= (2 * mini);\n        }\n        return sum;\n    }\n}\n```\n``` Py [ ]\nclass Solution:\n    def maxMatrixSum(self, matrix: List[List[int]]) -> int:\n        total_sum = 0\n        mini = float(\'inf\')\n        cnt = 0\n        \n        for row in matrix:\n            for val in row:\n                if val < 0:\n                    cnt += 1\n                mini = min(abs(val), mini)\n                total_sum += abs(val)\n        \n        if cnt % 2 == 1:\n            total_sum -= 2 * mini\n        \n        return total_sum\n```\n``` Go [ ]\nfunc maxMatrixSum(matrix [][]int) int64 {\n    var sum int64 = 0\n    mini := int64(^uint64(0) >> 1) // Max int64 value\n    cnt := 0\n    \n    for _, row := range matrix {\n        for _, val := range row {\n            if val < 0 {\n                cnt++\n            }\n            absVal := int64(val)\n            if absVal < 0 {\n                absVal = -absVal\n            }\n            if absVal < mini {\n                mini = absVal\n            }\n            sum += absVal\n        }\n    }\n    \n    if cnt%2 == 1 {\n        sum -= 2 * mini\n    }\n    return sum\n}\n```\n``` JavaScript [ ]\nvar maxMatrixSum = function(matrix) {\n    let sum = 0, mini = Number.MAX_SAFE_INTEGER, cnt = 0;\n    const n = matrix.length;\n    \n    for (let row = 0; row < n; row++) {\n        for (let col = 0; col < n; col++) {\n            const val = matrix[row][col];\n            if (val < 0) {\n                cnt++;\n            }\n            mini = Math.min(Math.abs(val), mini);\n            sum += Math.abs(val);\n        }\n    }\n    \n    if (cnt % 2 === 1) {\n        sum -= 2 * mini;\n    }\n    return sum;\n};\n```\n``` Ruby [ ]\ndef max_matrix_sum(matrix)\n    sum = 0\n    mini = Float::INFINITY\n    cnt = 0\n    \n    matrix.each do |row|\n        row.each do |val|\n            cnt += 1 if val < 0\n            mini = [mini, val.abs].min\n            sum += val.abs\n        end\n    end\n    \n    sum -= 2 * mini if cnt.odd?\n    sum\nend\n```
['Array', 'Greedy', 'Matrix', 'Python', 'C++', 'Java', 'Go', 'Python3', 'Ruby']