"""Leetcode 253. Meeting Rooms II (Premium)
Medium

URL: https://leetcode.com/problems/meeting-rooms-ii

Given an array of meeting time intervals consisting of start and end times
[[s1,e1],[s2,e2],...] (si < ei),
find the minimum number of conference rooms required.

Example1
Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2
Explanation:
We need two meeting rooms
room1: (0,30)
room2: (5,10),(15,20)

Example2
Input: intervals = [[7, 10], [2, 4]]
Output: 1
Explanation: 
Only need one meeting room
"""

class SolutionSortMinHeap(object):
    """
    @param intervals: an array of meeting time intervals
    @return: the minimum number of conference rooms required

    Time complexity: O(n*logn).
    Space complexity: O(n).
    """
    def minMeetingRooms(self, intervals):
        import heapq

        if not intervals or not intervals[0]:
            return 0

        # Sort intervals by start time.
        intervals.sort()

        # Use min heap to store end times.
        endtimes_minheap = []
        heapq.heappush(endtimes_minheap, intervals[0][1])

        for i in range(1, len(intervals)):
            # If next start time is after min end time, remove min end time.
            if intervals[i][0] >= endtimes_minheap[0]:
                heapq.heappop(endtimes_minheap)

            # Add next end time to min heap.
            heapq.heappush(endtimes_minheap, intervals[i][1])

        return len(endtimes_minheap)


def main():
    # Output: 2.
    intervals = [[0,30],[5,10],[15,20]]
    print SolutionSortMinHeap().minMeetingRooms(intervals)

    # Output: 1.
    intervals = [[7, 10], [2, 4]]
    print SolutionSortMinHeap().minMeetingRooms(intervals)


if __name__ == '__main__':
    main()

@@ -511,32 +511,39 @@
 ass SolutionSort
+Endtime
 MinHeap(object):
@@ -551,58 +551,33 @@
     
-%22%22%22%0A    @param intervals: an array of meeting time
+def minMeetingRooms(self,
  int
@@ -586,75 +586,93 @@
 vals
+):
 %0A    
-@return: the minimum number of conference rooms required
+    %22%22%22%0A        :type intervals: List%5BList%5Bint%5D%5D%0A        :rtype: int
 %0A%0A    
+ 
+   
 Time
@@ -691,24 +691,28 @@
  O(n*logn).%0A
+    
     Space co
@@ -735,53 +735,15 @@
     
-%22%22%22%0A    def minMeetingRooms(self, intervals):
+    %22%22%22
 %0A   
@@ -1481,32 +1481,39 @@
 int SolutionSort
+Endtime
 MinHeap().minMee
@@ -1607,16 +1607,23 @@
 tionSort
+Endtime
 MinHeap(

Revise docstring & class name