Skip to content

Commit fe62c16

Browse files
authored
Create 2402-meeting-rooms-iii.py
1 parent 999bb5b commit fe62c16

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

python/2402-meeting-rooms-iii.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def mostBooked(self, n: int, meetings: List[List[int]]) -> int:
3+
meetings.sort()
4+
5+
available = [i for i in range(n)]
6+
used = []
7+
count = [0] * n
8+
9+
for start, end in meetings:
10+
while used and start >= used[0][0]:
11+
_, room = heapq.heappop(used)
12+
heapq.heappush(available, room)
13+
14+
if not available:
15+
end_time, room = heapq.heappop(used)
16+
end = end_time + (end - start)
17+
heapq.heappush(available, room)
18+
19+
room = heapq.heappop(available)
20+
heapq.heappush(used, (end, room))
21+
count[room] += 1
22+
23+
return count.index(max(count))

0 commit comments

Comments
 (0)