medium

Interval List Intersections

You are given two lists of closed intervals; each list is sorted by start and contains pairwise disjoint intervals. Return the list of all intersections between an interval of the first list and one of the second.

Constraints
  • 0 ≤ len(A), len(B) ≤ 1000
  • 0 ≤ start ≤ end ≤ 10^9
  • Each list is sorted and disjoint
Examples
in: A = [[0,2],[5,10],[13,23],[24,25]], B = [[1,5],[8,12],[15,24],[25,26]]
out: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.