1229. Meeting Scheduler - cocoder39/coco39_LC GitHub Wiki

1229. Meeting Scheduler

same as 986 https://github.com/cocoder39/coco39_LC/wiki/986.-Interval-List-Intersections

when there is overlapping, moving forward based on end of interval if slots1[p1][1] < slots2[p2][1]. test case:

[10,12],[15, 25](/cocoder39/coco39_LC/wiki/10,12],[15,-25)
[0,100](/cocoder39/coco39_LC/wiki/0,100)
8
class Solution:
    def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
        slots1.sort()
        slots2.sort()

        idx1, idx2 = 0, 0
        while idx1 < len(slots1) and idx2 < len(slots2):
            start = max(slots1[idx1][0], slots2[idx2][0])
            end = min(slots1[idx1][1], slots2[idx2][1])

            if end - start >= duration:
                return [start, start + duration]
            
            if slots1[idx1][1] > slots2[idx2][1]:
                idx2 += 1
            else:
                idx1 += 1
        return []