DIY: Interval Lists Intersection

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

We'll cover the following

Problem statement

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

Input

The input is two arrays of intervals. Each array contains nested arrays 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]]

Output

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

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

Coding exercise

You need to implement the function intervalsIntersection(intervalsA, intervalsA), where intervalsA and intervalsB are the array of intervals. The function returns a array of intervals that contain the intervals’ intersection.

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