Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Intuition:
- At any moment, the number of rooms needed equals the number of meetings currently running.
- So we sort all start times and end times, and sweep through time using two pointers.
- If the next start is before the earliest end, one more meeting overlaps, so rooms++.
- Otherwise (start >= end), a meeting has finished and its room can be reused, so rooms--.
- The maximum overlap seen during this sweep is the minimum rooms required.
- """
- class Solution:
- def minMeetingRooms(self, start, end):
- start.sort()
- end.sort()
- ans=0
- i,j=0,0
- cur=0
- while i<len(start):
- if start[i]<end[j]:
- i+=1
- cur+=1
- else:
- j+=1
- cur-=1
- ans=max(ans,cur)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment