Interval List Intersections
MediumQuestion
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.
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].
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].
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
Remember to understand the problem and plan your approach before you start coding.