< Summary

Information
Class: LeetCode.Algorithms.DivideIntervalsIntoMinimumNumberOfGroups.DivideIntervalsIntoMinimumNumberOfGroupsLineSweep
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DivideIntervalsIntoMinimumNumberOfGroups\DivideIntervalsIntoMinimumNumberOfGroupsLineSweep.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MinGroups(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DivideIntervalsIntoMinimumNumberOfGroups\DivideIntervalsIntoMinimumNumberOfGroupsLineSweep.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.DivideIntervalsIntoMinimumNumberOfGroups;
 13
 14/// <inheritdoc />
 15public class DivideIntervalsIntoMinimumNumberOfGroupsLineSweep : IDivideIntervalsIntoMinimumNumberOfGroups
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="intervals"></param>
 22    /// <returns></returns>
 23    public int MinGroups(int[][] intervals)
 224    {
 225        var rangeStart = int.MaxValue;
 226        var rangeEnd = int.MinValue;
 27
 2428        foreach (var interval in intervals)
 929        {
 930            rangeStart = Math.Min(rangeStart, interval[0]);
 931            rangeEnd = Math.Max(rangeEnd, interval[1]);
 932        }
 33
 234        var pointToCount = new int[rangeEnd + 2];
 35
 2436        foreach (var interval in intervals)
 937        {
 938            pointToCount[interval[0]]++;
 939            pointToCount[interval[1] + 1]--;
 940        }
 41
 242        var concurrentIntervals = 0;
 243        var maxConcurrentIntervals = 0;
 44
 5045        for (var i = rangeStart; i <= rangeEnd; i++)
 2346        {
 2347            concurrentIntervals += pointToCount[i];
 48
 2349            maxConcurrentIntervals = Math.Max(maxConcurrentIntervals, concurrentIntervals);
 2350        }
 51
 252        return maxConcurrentIntervals;
 253    }
 54}

Methods/Properties

MinGroups(System.Int32[][])