Interval List Intersections

Medium

Question

You're given two lists of intervals. The intervals inside each list don't overlap each other. Return a new list of every spot where an interval from one list intersects an interval from the other.

Both lists are already sorted by each interval's first value.

Each interval's first value is always less than or equal to its second value.

Intervals example 1

Input: list_a = [[0, 3], [4, 5], [6, 7]], list_b = [[1, 2], [7, 7]]

Output: [[1, 2], [7, 7]]

[0, 3] and [1, 2] intersect at [1, 2]. [6, 7] and [7, 7] intersect at [7, 7].

Intervals example 2

Input: list_a = [[3, 3], [4, 6], [7, 7]], list_b = [[1, 5]]

Output: [[3, 3], [4, 5]]

[3, 3] and [4, 6] both overlap [1, 5]. They intersect it at [3, 3] and [4, 5].

Intervals example 3

Input: list_a = [[0, 3], [4, 5], [6, 7]], list_b = []

Output: []

Nothing can intersect because the second list is empty.

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What is the list of interval intersections of these two lists? list_a = [[1, 4], [9, 15]], list_b = [[2, 6], [8, 10], [13, 14]]
[]
[[1, 6], [8, 15]]
[[2, 4], [9, 10], [13, 14]]
[[1, 1], [5, 6], [8, 8], [11, 12], [15, 15]]

Remember to understand the problem and plan your approach before you start coding.