issues
search
chenye-814
/
DTSTRCT-ALGRTHM
0
stars
0
forks
source link
Jan-03 Meeting Rooms III
#8
Open
chenye-814
opened
1 year ago
chenye-814
commented
1 year ago
https://leetcode.com/problems/meeting-rooms-iii/
chenye-814
commented
1 year ago
view code
```py from heapq import heappush, heappop class Solution: def mostBooked(self, n: int, meetings: List[List[int]]) -> int: meetings.sort(key=lambda x:x[0]) available_rooms: List[(int,int)] = [] occupied_rooms: List[(int,int,int)] = [] for i in range(n): available_rooms.append((i, 0)) ans, max_cnt = -1, 0 for meeting in meetings: while occupied_rooms and occupied_rooms[0][0] <= meeting[0]: heappush(available_rooms, heappop(occupied_rooms)[1:]) if available_rooms: room, cnt = heappop(available_rooms) next_release = meeting[1] else: release, room, cnt = heappop(occupied_rooms) next_release = release+meeting[1]-meeting[0] cnt += 1 if cnt > max_cnt: max_cnt = cnt ans = room elif cnt == max_cnt and room < ans: ans = room heappush(occupied_rooms, (next_release, room, cnt)) return ans ```
https://leetcode.com/problems/meeting-rooms-iii/