1229. Meeting Scheduler (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution(object):
    def minAvailableDuration(self, slots1, slots2, duration):
        """
        :type slots1: List[List[int]]
        :type slots2: List[List[int]]
        :type duration: int
        :rtype: List[int]
        """
        slots1.sort()
        slots2.sort()
        i = j = 0
        while i < len(slots1) and j < len(slots2):
            (a1, b1), (a2, b2) = slots1[i], slots2[j]
            arr = sorted([a1, a2, b1, b2])
            if a1 <= b2 and a2 <= b1 and arr[2] - arr[1] >= duration:
                return [arr[1], arr[1] + duration]
            if b1 > b2:
                j += 1
            else:
                i += 1
        return []