Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Interval List Intersections

XPChallenge Points: 20
levelLevel: Medium

You are given two sorted lists of non-overlapping (disjoint) intervals:

  • listA = [[start1, end1], [start2, end2], ...]

  • listB = [[startX, endX], [startY, endY], ...]

Your task is to find all intervals where they overlap.

If two intervals overlap, the overlapping portion will form another interval:

Overlap = [ max(startA, startB), min(endA, endB) ]

If there is no overlap, skip to the next interval.

Return all such overlapping intervals.

Example 1:

Input: listA = [[2,6],[8,11]] listB = [[1,4],[7,10],[12,14]]

Output: [[2,4],[8,10]]

Explanation:

Overlap between [2,6] and [1,4] → [2,4] Overlap between [8,11] and [7,10] → [8,10]

Example 2:

Input: listA = [[1,2],[5,7]] listB = [[3,4],[6,8]]

Output: [[6,7]]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result