You get two lists of intervals. Each is sorted, and inside one list no two intervals overlap. Return every common part of an interval from the first list and an interval from the second, in order. A common part can be a single point. Our example: A = [1, 3], [5, 9], [11, 12], B = [0, 2], [4, 6], [8, 12] — the answer is [1, 2], [5, 6], [8, 9], [11, 12].
input
firstList, secondList: two lists of intervals [start, end]. Each list is sorted, and inside one list no two intervals overlap or touch. A list may be empty.
returns
Every common part of an interval of firstList and an interval of secondList, as [start, end], in order. A common part can be a single point, like [3, 3] of [1, 3] and [3, 5].
constraints
0 ≤ firstList.length, secondList.length ≤ 1000
1 ≤ firstList.length + secondList.length
0 ≤ startᵢ < endᵢ ≤ 10⁹, and endᵢ < startᵢ₊₁ in each list
our 11 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.