Problem
You get two lists of closed intervals, first and second. Each list is sorted and its own intervals are pairwise disjoint. Return the intersection of the two lists: every stretch covered by an interval from both lists, in sorted order. Closed means the ends are included, so [1, 5] and [5, 8] intersect at [5, 5].
Example 1
first = [[0, 2], [5, 10], [13, 23], [24, 25]]
Example 2
second = [[1, 5], [8, 12], [15, 24], [25, 26]]
Example 3
→ [[1, 2], [5, 5], [8, 10], [15, 23], [24, 24], [25, 25]]
Example 4
- Input
- first = [[1, 3], [5, 9]], second = []
- Output
- []
Constraints
0 <= first.length, second.length <= 10000 <= start < end <= 10^9Within each list, every interval ends before the next one starts.