Skip to content

Instantly share code, notes, and snippets.

@athulmurali
Last active June 6, 2019 04:57
Show Gist options
  • Save athulmurali/a88fa9c7d8687d34d1ed357dc16b3c70 to your computer and use it in GitHub Desktop.
Save athulmurali/a88fa9c7d8687d34d1ed357dc16b3c70 to your computer and use it in GitHub Desktop.
Meeting Rooms ||
# Definition for an interval.
# class Interval:
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution:
def minMeetingRooms(self, intervals: List[Interval]) -> int:
import heapq
heap = []
max_rooms = 0
intervals.sort(key=lambda x: x.start)
for ent in intervals:
heapq.heappush(heap, ent.end)
while heap and heap[0] <= ent.start:
heapq.heappop(heap)
max_rooms = max(len(heap),max_rooms)
return max_rooms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment