Saturday, April 7, 2018

Merging overlapping lists

You are given two lists of intervals, A and B.
In A, the intervals are sorted by their starting points. None of the intervals within A overlap.
Likewise, in B, the intervals are sorted by their starting points. None of the intervals within B overlap.
Return the intervals that overlap between the two lists.
Example:
A: {[0,4], [7,12]}
B: {[1,3], [5,8], [9,11]}
Return:
{[1,3], [7,8], [9,11]}
How would you do this?

Here is a solution

No comments:

Post a Comment