986. Interval List Intersections
Practice Interval List Intersections for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
firstList and secondList are each a list of closed intervals [start, end], pairwise disjoint and sorted. Return the intersection of the two lists: every non-empty overlap between an interval of the first list and an interval of the second, in sorted order. A single shared point such as [5, 5] counts.
Example
firstList = [[0,2],[5,10],[13,23],[24,25]]
secondList = [[1,5],[8,12],[15,24],[25,26]]
-> [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
Constraints
- 0 <= firstList.length, secondList.length <= 1000
- 0 <= start < end <= 10^9; within each list end_i < start_{i+1}