Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Identify All Interval Overlaps

You are given two lists of intervals, first and second. Each list is sorted by start time and contains disjoint intervals (no two intervals within the same list overlap or touch).

Return a list of intervals representing the intersection of the two lists — every range of points that lies in both an interval from first and an interval from second. The output should also be sorted and disjoint.

Example 1

Input:
  first  = [[0, 2], [5, 10], [13, 23], [24, 25]]
  second = [[1, 5], [8, 12], [15, 24], [25, 26]]
Output: [[1, 2], [5, 5], [8, 10], [15, 23], [24, 24], [25, 25]]

Example 2

Input:
  first  = [[1, 3], [5, 9]]
  second = [[2, 4]]
Output: [[2, 3]]

Constraints

  • 0 <= first.length, second.length <= 10^3
  • Both lists are sorted by start time and internally disjoint.
  • 0 <= start_i <= end_i <= 10^9

Share this question

← Back to Intervals practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.