< Summary

Information
Class: LeetCode.Algorithms.TwoBestNonOverlappingEvents.TwoBestNonOverlappingEventsPriorityQueue
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoBestNonOverlappingEvents\TwoBestNonOverlappingEventsPriorityQueue.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 52
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
MaxTwoEvents(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoBestNonOverlappingEvents\TwoBestNonOverlappingEventsPriorityQueue.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.TwoBestNonOverlappingEvents;
 13
 14/// <inheritdoc />
 15public class TwoBestNonOverlappingEventsPriorityQueue : ITwoBestNonOverlappingEvents
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="events"></param>
 22    /// <returns></returns>
 23    public int MaxTwoEvents(int[][] events)
 324    {
 1225        Array.Sort(events, (a, b) => a[0] - b[0]);
 26
 327        var completedEventsPriorityQueue = new PriorityQueue<(int EndTime, int Value), int>();
 28
 329        var maxValueBeforeCurrent = 0;
 330        var maxSum = 0;
 31
 2732        foreach (var @event in events)
 933        {
 934            var startTime = @event[0];
 935            var endTime = @event[1];
 936            var value = @event[2];
 37
 1338            while (completedEventsPriorityQueue.Count > 0 && completedEventsPriorityQueue.Peek().EndTime < startTime)
 439            {
 440                var completedEvent = completedEventsPriorityQueue.Dequeue();
 41
 442                maxValueBeforeCurrent = Math.Max(maxValueBeforeCurrent, completedEvent.Value);
 443            }
 44
 945            maxSum = Math.Max(maxSum, maxValueBeforeCurrent + value);
 46
 947            completedEventsPriorityQueue.Enqueue((endTime, value), endTime);
 948        }
 49
 350        return maxSum;
 351    }
 52}

Methods/Properties

MaxTwoEvents(System.Int32[][])