< Summary

Information
Class: LeetCode.Algorithms.FindValidMatrixGivenRowAndColumnSums.FindValidMatrixGivenRowAndColumnSumsBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindValidMatrixGivenRowAndColumnSums\FindValidMatrixGivenRowAndColumnSumsBruteForce.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 58
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
RestoreMatrix(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindValidMatrixGivenRowAndColumnSums\FindValidMatrixGivenRowAndColumnSumsBruteForce.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.FindValidMatrixGivenRowAndColumnSums;
 13
 14/// <inheritdoc />
 15public class FindValidMatrixGivenRowAndColumnSumsBruteForce : IFindValidMatrixGivenRowAndColumnSums
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m^2 * n)
 19    ///     Space complexity - O(m * n)
 20    /// </summary>
 21    /// <param name="rowSum"></param>
 22    /// <param name="colSum"></param>
 23    /// <returns></returns>
 24    public int[][] RestoreMatrix(int[] rowSum, int[] colSum)
 225    {
 226        var result = new int[rowSum.Length][];
 27
 1428        for (var i = 0; i < result.Length; i++)
 529        {
 530            result[i] = new int[colSum.Length];
 31
 532            var currentRowSum = 0;
 33
 1834            for (var j = 0; j < result[i].Length; j++)
 935            {
 936                var currentColSum = colSum[j];
 37
 3838                for (var k = 0; k < i; k++)
 1039                {
 1040                    currentColSum -= result[k][j];
 1041                }
 42
 943                var sum = Math.Min(currentColSum, rowSum[i] - currentRowSum);
 44
 945                result[i][j] = sum;
 46
 947                currentRowSum += sum;
 48
 949                if (currentRowSum >= rowSum[i])
 550                {
 551                    break;
 52                }
 453            }
 554        }
 55
 256        return result;
 257    }
 58}