56. Merge Intervals
from sortedcontainers import SortedDict
class Solution:
    def merge(self, intervals: List[List[int]]) -> List[List[int]]:
        maps = SortedDict()
        for v1, v2 in intervals:
            maps[v1] = maps.get(v1, 0) + 1
            maps[v2] = maps.get(v2, 0) - 1
        
        res = []
        current = 0
        pair = []
        for key, value in maps.items():
            if current == 0 and not pair:
                pair.append(key)
            current += value
            if current == 0 and pair:
                pair.append(key)
                res.append(pair)
                pair = []
        return res