Two colleagues each publish their free time as a list of closed intervals [start, end], sorted and pairwise disjoint. Return every interval when both are free, as a sorted list of closed intervals. A single shared moment counts and is returned as [x, x].
Examples
Input: a = [[1, 4], [7, 12], [15, 20], [22, 23]]
b = [[2, 7], [10, 13], [16, 22], [23, 25]]
Output: [[2, 4], [7, 7], [10, 12], [16, 20], [22, 22], [23, 23]]
Input: a = [[1, 3]], b = [[4, 6]]
Output: []
Constraints
0 <= len(a), len(b) <= 5 * 10**4,0 <= start <= end <= 10**9.- Target complexity: O(n + m).
Goals
- Compute the overlap of two closed intervals with max/min
- Decide which pointer to advance after each comparison