#986
Interval List Intersections
pupil · 515 · lc medium +28 · verified · 73% accepted · 5,900 likes · top 83%
Description
Given two sorted, pairwise-disjoint lists of closed intervals — firstList and secondList — return every closed interval that is an intersection between some interval in firstList and some interval in secondList.
Example 1:
Input: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]
Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
Example 2:
Input: firstList = [[1,3],[5,9]], secondList = []
Output: []
Code
1
2
3