class Solution:
    def maxEvents(self, events: List[List[int]]) -> int:
        """
        1. sort by start 
        2. put the end time of events starting before current date into PQ 
        3. pop events that end earlier than current date off the PQ 
        4. cnt + 1, date +1, pop one event out 
        """
        events.sort()
        n = len(events)
        cnt, cur_date, i = 0, 0, 0
        hp = []
        while i < n or hp:
            if i < n and not hp:
                cur_date = events[i][0]
            
            while i < n and events[i][0] <= cur_date :
                heapq.heappush(hp,events[i][1])
                i += 1
           
            while hp and hp[0] < cur_date:
                heapq.heappop(hp)
                
            if hp:
                heapq.heappop(hp)
                cnt += 1 
                
            cur_date += 1
            
        return cnt  


        class Solution: