< Summary

Information
Class: LeetCode.Algorithms.CountCoveredBuildings.CountCoveredBuildingsSimulation
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountCoveredBuildings\CountCoveredBuildingsSimulation.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountCoveredBuildings(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountCoveredBuildings\CountCoveredBuildingsSimulation.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 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.CountCoveredBuildings;
 13
 14/// <inheritdoc />
 15public sealed class CountCoveredBuildingsSimulation : ICountCoveredBuildings
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m + n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="n"></param>
 22    /// <param name="buildings"></param>
 23    /// <returns></returns>
 24    public int CountCoveredBuildings(int n, int[][] buildings)
 325    {
 326        Span<int> maxRow = stackalloc int[n + 1];
 327        Span<int> minRow = stackalloc int[n + 1];
 328        Span<int> maxCol = stackalloc int[n + 1];
 329        Span<int> minCol = stackalloc int[n + 1];
 30
 331        minRow.Fill(n + 1);
 332        minCol.Fill(n + 1);
 33
 3434        for (var i = 0; i < buildings.Length; i++)
 1435        {
 1436            var building = buildings[i];
 37
 1438            var x = building[0];
 1439            var y = building[1];
 40
 1441            maxRow[y] = Math.Max(maxRow[y], x);
 1442            minRow[y] = Math.Min(minRow[y], x);
 1443            maxCol[x] = Math.Max(maxCol[x], y);
 1444            minCol[x] = Math.Min(minCol[x], y);
 1445        }
 46
 347        var count = 0;
 48
 3449        for (var i = 0; i < buildings.Length; i++)
 1450        {
 1451            var building = buildings[i];
 52
 1453            var x = building[0];
 1454            var y = building[1];
 55
 1456            if (x > minRow[y] && x < maxRow[y] && y > minCol[x] && y < maxCol[x])
 257            {
 258                count++;
 259            }
 1460        }
 61
 362        return count;
 363    }
 64}