< Summary

Information
Class: LeetCode.Algorithms.CheckIfGridCanBeCutIntoSections.CheckIfGridCanBeCutIntoSectionsSorting
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfGridCanBeCutIntoSections\CheckIfGridCanBeCutIntoSectionsSorting.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 56
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
CheckValidCuts(...)100%22100%
CheckCuts(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfGridCanBeCutIntoSections\CheckIfGridCanBeCutIntoSectionsSorting.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.CheckIfGridCanBeCutIntoSections;
 13
 14/// <inheritdoc />
 15public class CheckIfGridCanBeCutIntoSectionsSorting : ICheckIfGridCanBeCutIntoSections
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(log n)
 20    /// </summary>
 21    /// <param name="n"></param>
 22    /// <param name="rectangles"></param>
 23    /// <returns></returns>
 24    public bool CheckValidCuts(int n, int[][] rectangles)
 325    {
 326        return CheckCuts(rectangles, 0) || CheckCuts(rectangles, 1);
 327    }
 28
 29    private static bool CheckCuts(int[][] rectangles, int dimension)
 530    {
 2931        Array.Sort(rectangles, (a, b) => a[dimension].CompareTo(b[dimension]));
 32
 533        var gapCount = 0;
 534        var furthestEnd = rectangles[0][dimension + 2];
 35
 4036        for (var i = 1; i < rectangles.Length; i++)
 1737        {
 1738            var start = rectangles[i][dimension];
 1739            var end = rectangles[i][dimension + 2];
 40
 1741            if (furthestEnd <= start)
 642            {
 643                gapCount++;
 44
 645                if (gapCount >= 2)
 246                {
 247                    return true;
 48                }
 449            }
 50
 1551            furthestEnd = Math.Max(furthestEnd, end);
 1552        }
 53
 354        return false;
 555    }
 56}