✅easiest-soln | Adobe🔥
#ReviseWithArsh #6Companies30Days Challenge 2023\nChallenge Company 3 : Adobe\nQ10. Max matrix Sum\n\n# Complexity\n- Time complexity:  O(n*m), where n and m ar
**#ReviseWithArsh #6Companies30Days Challenge 2023\nChallenge Company 3 : Adobe\nQ10. Max matrix Sum**\n\n# Complexity\n- Time complexity:  O(n*m), where n and m are the number of rows and columns in the matrix respectively.\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    //function to calculate the maximum matrix sum\n    long long maxMatrixSum(vector<vector<int>>& matrix) {\n    long long int totalSum = 0; // variable to store the total sum of the matrix\n    bool zeroExists = false; // variable to check if there is any 0 in the matrix\n    int negativeCount = 0; // variable to store the count of negative numbers in the matrix\n    int minimumAbsoluteValue = INT_MAX; // variable to store the minimum absolute value of the matrix\n        //iterating through the matrix\n    for(auto it: matrix)\n    {\n        for(auto i: it)\n        {\n            if(i==0)\n                zeroExists = true; // setting the zeroExists variable to true if there is 0 in the matrix\n            if(i<0)\n                negativeCount++; // incrementing the negativeCount variable if the current number is negative\n            totalSum += abs(i); // adding the absolute value of the current number to the totalSum\n            if(abs(i)<minimumAbsoluteValue)\n                minimumAbsoluteValue = abs(i); // updating the minimumAbsoluteValue variable if the current absolute value is less than the current value\n        }\n    }\n    //if there is zero or even number of negative numbers\n    if(zeroExists || negativeCount%2==0)\n        return totalSum;\n    return totalSum-2*minimumAbsoluteValue; // returning the totalSum - 2* minimumAbsoluteValue\n}\n};\n\n```\n![upvotee.jpg](https://assets.leetcode.com/users/images/9acdd574-622b-4fbf-814a-2eea1920d178_1674020092.05819.jpeg)\n
['C++']