< Summary

Information
Class: LeetCode.Algorithms.MaximumMatrixSum.MaximumMatrixSumBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumMatrixSum\MaximumMatrixSumBruteForce.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MaxMatrixSum(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumMatrixSum\MaximumMatrixSumBruteForce.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.MaximumMatrixSum;
 13
 14/// <inheritdoc />
 15public class MaximumMatrixSumBruteForce : IMaximumMatrixSum
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="matrix"></param>
 22    /// <returns></returns>
 23    public long MaxMatrixSum(int[][] matrix)
 224    {
 225        long sum = 0;
 226        var minAbsValue = int.MaxValue;
 227        var negativeCount = 0;
 28
 1629        foreach (var row in matrix)
 530        {
 4131            foreach (var cell in row)
 1332            {
 1333                sum += Math.Abs(cell);
 34
 1335                if (cell < 0)
 536                {
 537                    negativeCount++;
 538                }
 39
 1340                minAbsValue = Math.Min(minAbsValue, Math.Abs(cell));
 1341            }
 542        }
 43
 244        if (negativeCount % 2 != 0)
 145        {
 146            sum -= 2 * minAbsValue;
 147        }
 48
 249        return sum;
 250    }
 51}

Methods/Properties

MaxMatrixSum(System.Int32[][])