← 返回 meta 的题目列表Interval List Intersection
类型:online_judge
Given two lists of closed intervals A and B, find their intersections. Each list of intervals is pairwise-disjoint and in sorted order.
Input Format:
A: [[1, 5], [10, 14], [16, 18]]
B: [[2, 6], [8, 10], [11, 20]]
Output Format:
List of intersection intervals in ascending order, e.g., [[2, 5], [10, 10], [16, 18]]
Requirement: Find all the intersection intervals and return them sorted in ascending order.
Note: The intersection of interval [a, b] with interval [x, y] is the interval [max(a, x), min(b, y)], if it forms a valid interval.
Test Cases:
A: [[1, 3], [5, 9]], B: [[2, 5]] => [[2, 3], [5, 5]]
A: [[1, 7]], B: [[3, 10]] => [[3, 7]]
A: [[1, 3], [5, 6]], B: [[7, 9]] => []
A: [[1, 3]], B: [[3, 5]] => [[3, 3]]
A: [], B: [[1, 2], [3, 4]] => []
Example
Input
[[1, 3], [5, 9]] [[2, 5]]