-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountMeetingRoom.py
35 lines (28 loc) · 1.01 KB
/
CountMeetingRoom.py
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
32
33
34
35
"""Question: You have been given log files data of a company for the past 5 year which contains information
about meetings that happened in the company. The log file has the following format meetingid : starttime,
endtime where starttime and endtime are unix timestamps. Figure out how many meeting rooms must exist
at the company for this data to be accurate.
Assume each meeting is represented by a tuple (meetingID, startTime, endTime), and the list of tuples is sorted
based on the startTime.
"""
import queue
def countRoom(list):
pq = queue.PriorityQueue()
count = 0
max = 0
for item in list:
#item = [meetingID, startTime, endTime]
if not pq.empty():
top = pq.get()
if top[0] > item[1]:
pq.put(top)
count += 1
if max < count:
max = count
else:
count += 1
pq.put([item[2],item[0]])
return max
#Test case
list = [['a',1,4],['a',1,100],['b',2,4],['c',3,6],['d',5,10],['f',7,9],['g',10,12],['h',11,15]]
print(countRoom(list))