< Summary

Information
Class: LeetCode.Algorithms.MinimumTimeDifference.MinimumTimeDifferenceBucketSort
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumTimeDifference\MinimumTimeDifferenceBucketSort.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 67
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
FindMinDifferenceInternal(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumTimeDifference\MinimumTimeDifferenceBucketSort.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.MinimumTimeDifference;
 13
 14/// <inheritdoc />
 15public class MinimumTimeDifferenceBucketSort : MinimumTimeDifferenceBase
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="timePoints"></param>
 22    /// <returns></returns>
 23    public override int FindMinDifferenceInternal(IList<string> timePoints)
 724    {
 725        var minutes = new bool[DayMinutes];
 26
 6827        foreach (var timePoint in timePoints)
 2428        {
 2429            var totalMinutes = (int)TimeSpan.Parse(timePoint).TotalMinutes;
 30
 2431            if (minutes[totalMinutes])
 132            {
 133                return 0;
 34            }
 35
 2336            minutes[totalMinutes] = true;
 2337        }
 38
 639        var minDifference = int.MaxValue;
 640        var first = -1;
 641        var last = -1;
 642        var previous = -1;
 43
 1729244        for (var i = 0; i < DayMinutes; i++)
 864045        {
 864046            if (!minutes[i])
 861947            {
 861948                continue;
 49            }
 50
 2151            if (first == -1)
 652            {
 653                first = i;
 654            }
 55
 2156            if (previous != -1)
 1557            {
 1558                minDifference = Math.Min(minDifference, i - previous);
 1559            }
 60
 2161            previous = i;
 2162            last = i;
 2163        }
 64
 665        return Math.Min(minDifference, DayMinutes + first - last);
 766    }
 67}