educative.io

Educative

Given a list of intervals, find the point where the maximum number of intervals overlap

Hi,

def max_intervals_overlap(meetings):
  meetings.sort(key=lambda x: x.start)

  maxOverlap = 0
  minHeap = []
  for meeting in meetings:
    # remove all the meetings that have ended
    while(len(minHeap) > 0 and meeting.start > minHeap[0].end):
      heappop(minHeap)
    # add the current meeting into min_heap
    heappush(minHeap, meeting)
    # all active meetings are in the min_heap, so we need rooms for all of them.
    maxOverlap = max(maxOverlap, len(minHeap))
  return maxOverlap

Is the above solution is correct?

Hi @Venkatesh3,

Yes, your solution is correct.