Interval List Intersections
Given two lists of closed intervals, firstList and secondList, each sorted and internally pairwise-disjoint, return the intersection of the two lists: every interval covered by BOTH, in sorted order.
Open official problem prompt ↗Produce every time span that appears in both schedules, given two clean sorted timelines.
Two people slide their finger down their own sorted list of busy blocks. At each moment they compare the block each finger points to; where the blocks overlap they note the shared window, then whoever's block finishes first moves their finger down.
- Input
- firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]
- Output
- [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
- Why
- Each output interval is the overlap of one interval from each list, e.g. [0,2] ∩ [1,5] = [1,2].
0 <= firstList.length, secondList.length <= 1000firstList.length + secondList.length >= 10 <= start_i <= end_i <= 10^9Each list is sorted and pairwise disjoint