< Summary

Information
Class: LeetCode.Algorithms.CountServersThatCommunicate.CountServersThatCommunicateCounting
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountServersThatCommunicate\CountServersThatCommunicateCounting.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountServers(...)100%1616100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountServersThatCommunicate\CountServersThatCommunicateCounting.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.CountServersThatCommunicate;
 13
 14/// <inheritdoc />
 15public class CountServersThatCommunicateCounting : ICountServersThatCommunicate
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n)
 19    ///     Space complexity - O(m + n)
 20    /// </summary>
 21    /// <param name="grid"></param>
 22    /// <returns></returns>
 23    public int CountServers(int[][] grid)
 324    {
 325        var m = grid.Length;
 326        var n = grid[0].Length;
 27
 328        var rowCount = new int[m];
 329        var colCount = new int[n];
 30
 2231        for (var i = 0; i < m; i++)
 832        {
 6433            for (var j = 0; j < n; j++)
 2434            {
 2435                if (grid[i][j] == 0)
 1436                {
 1437                    continue;
 38                }
 39
 1040                rowCount[i]++;
 1041                colCount[j]++;
 1042            }
 843        }
 44
 345        var result = 0;
 46
 2247        for (var i = 0; i < m; i++)
 848        {
 6449            for (var j = 0; j < n; j++)
 2450            {
 2451                if (grid[i][j] == 1 && (rowCount[i] > 1 || colCount[j] > 1))
 752                {
 753                    result++;
 754                }
 2455            }
 856        }
 57
 358        return result;
 359    }
 60}

Methods/Properties

CountServers(System.Int32[][])