-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum_events.py
More file actions
32 lines (25 loc) · 843 Bytes
/
maximum_events.py
File metadata and controls
32 lines (25 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from heapq import heappush,heapify,heappop
def max_events(events):
attending = 0
events.sort()
position = 0
time = 1
last_position = len(events)
outstanding = []
heapify(outstanding)
heappush(outstanding,0)
while (position < last_position or outstanding):
if not outstanding:
time = max(time,events[position][0])
while position < last_position and time == events[position][0]:
heappush(outstanding, events[position][1])
position+=1
while outstanding and outstanding[0] < time:
heappop(outstanding)
if outstanding:
attending +=1
heappop(outstanding)
time+=1
return attending
alt_list = [[1,2],[2,3],[3,4]]
print(max_events([[1,2],[1,2],[3,3],[1,5],[1,5]]))