Interval List Intersections

Given two lists of disjoint, sorted intervals `firstList` and `secondList`, return the intersection of these two interval lists. **Pattern focus:** Merge Overlapping Ranges. Handle cases where intervals overlap at edges.

Examples

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]]

Explanation:

Intersecting intervals produce overlapping segments.

Example 2:

Input:

firstList = [[1,3],[6,7]]
secondList = [[2,4],[7,8]]

Output:

[[2,3],[7,7]]

Explanation:

Intersection of [1,3]∩[2,4]=[2,3] and [6,7]∩[7,8]=[7,7].

Loading...
Interval List Intersections - Intervals