imashutosh51

Meeting Rooms II

Feb 7th, 2026
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. """
  2. Intuition:
  3. At any moment, the number of rooms needed equals the number of meetings currently running.
  4. So we sort all start times and end times, and sweep through time using two pointers.
  5. If the next start is before the earliest end, one more meeting overlaps, so rooms++.
  6. Otherwise (start >= end), a meeting has finished and its room can be reused, so rooms--.
  7. The maximum overlap seen during this sweep is the minimum rooms required.
  8. """
  9.  
  10. class Solution:
  11.     def minMeetingRooms(self, start, end):
  12.         start.sort()
  13.         end.sort()
  14.         ans=0
  15.         i,j=0,0
  16.         cur=0
  17.         while i<len(start):
  18.             if start[i]<end[j]:
  19.                 i+=1
  20.                 cur+=1
  21.             else:
  22.                 j+=1
  23.                 cur-=1
  24.             ans=max(ans,cur)
  25.         return ans
  26.            
  27.        
  28.  
Advertisement
Add Comment
Please, Sign In to add comment