DIY: Interval Lists Intersection

Solve the interview question "Interval Lists Intersection" in this lesson.

Problem statement

In this problem, you are provided with two lists of intervals. Each list contains a disjoint and intervals. Your job is to find the intersection of these lists of intervals.


The input is two lists of intervals. Each list contains nested lists that have two integers representing the starting and ending points of the interval. The following is an example input:

[[1, 3], [5, 6], [7, 9]]
[[2, 4], [6, 7], [8, 10]]


The output is a list that contains the intervals’ intersection. The following is an example output:

[[2, 3], [8, 9]]

Coding exercise

You need to implement the function intervals_intersection(intervals_a, intervals_b), where intervals_a and intervals_b are the lists of intervals. The function returns a list of intervals that contain the intervals’ intersection.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.