1
# Runtime: 1160 ms (Top 93.22%) | Memory: 61.6 MB (Top 51.45%)3
def maxEvents(self, events):5
:type events: List[List[int]]8
events = sorted(events, key=lambda x: x[0])12
total_number_of_days = max(end for start, end in events)13
total_events_attended = 014
# total_number_of_days+1 because I want to include the last day15
for day in range(1, total_number_of_days + 1):17
# Add all the events that can be started on that day18
while event_id < len(events) and events[event_id][0] == day:19
heapq.heappush(min_heap, events[event_id][1])22
# while there is something in heap and the event should have been completed before the current day23
# remove those evenets and consider them not attended24
while min_heap and min_heap[0] < day:25
heapq.heappop(min_heap)27
# if theere is an event present in heap28
# lets mark 1 of those events as complted today and add it to29
# total_events_attended32
heapq.heappop(min_heap)33
total_events_attended += 134
return total_events_attended