We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5f08c01 commit c8d1ff9Copy full SHA for c8d1ff9
meeting-rooms-ii/yolophg.py
@@ -0,0 +1,22 @@
1
+ # Time Complexity: O(n log n) -> sorting takes O(n log n), and heap operations take O(log n) per interval.
2
+ # Space Complexity: O(n) -> in the worst case, store all meetings in the heap.
3
+
4
+class Solution:
5
+ def minMeetingRooms(self, intervals: List[List[int]]) -> int:
6
+ if not intervals:
7
+ return 0
8
9
+ # sort meetings by start time.
10
+ intervals.sort()
11
12
+ # heap to keep track of meeting end times.
13
+ min_heap = []
14
15
+ for start, end in intervals:
16
+ if min_heap and min_heap[0] <= start:
17
+ # remove the meeting that has ended.
18
+ heapq.heappop(min_heap)
19
+ # add the current meeting's end time.
20
+ heapq.heappush(min_heap, end)
21
22
+ return len(min_heap)
0 commit comments