< Summary

Information
Class: LeetCode.Algorithms.MaximumNumberOfEventsThatCanBeAttended.MaximumNumberOfEventsThatCanBeAttendedPriorityQueue
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumNumberOfEventsThatCanBeAttended\MaximumNumberOfEventsThatCanBeAttendedPriorityQueue.cs
Line coverage
88%
Covered lines: 23
Uncovered lines: 3
Coverable lines: 26
Total lines: 61
Line coverage: 88.4%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MaxEvents(...)92.85%141488.46%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumNumberOfEventsThatCanBeAttended\MaximumNumberOfEventsThatCanBeAttendedPriorityQueue.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.MaximumNumberOfEventsThatCanBeAttended;
 13
 14/// <inheritdoc />
 15public class MaximumNumberOfEventsThatCanBeAttendedPriorityQueue : IMaximumNumberOfEventsThatCanBeAttended
 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 MaxEvents(int[][] events)
 224    {
 1025        Array.Sort(events, (event1, event2) => event1[0] - event2[0]);
 26
 227        var maxEvents = 0;
 28
 229        var priorityQueue = new PriorityQueue<int, int>();
 30
 231        var eventIndex = 0;
 32
 233        var day = 0;
 34
 1135        while (eventIndex < events.Length || priorityQueue.Count > 0)
 936        {
 1637            while (eventIndex < events.Length && events[eventIndex][0] <= day)
 738            {
 739                priorityQueue.Enqueue(events[eventIndex][1], events[eventIndex][1]);
 40
 741                eventIndex++;
 742            }
 43
 944            while (priorityQueue.Count > 0 && priorityQueue.Peek() < day)
 045            {
 046                priorityQueue.Dequeue();
 047            }
 48
 949            if (priorityQueue.Count > 0)
 750            {
 751                priorityQueue.Dequeue();
 52
 753                maxEvents++;
 754            }
 55
 956            day++;
 957        }
 58
 259        return maxEvents;
 260    }
 61}

Methods/Properties

MaxEvents(System.Int32[][])