Solution: Interval List Intersections

Let's solve the Interval List Intersections problem using the Merge Intervals pattern.

Statement

For two lists of closed intervals given as input, interval_list_a and interval_list_b, where each interval has its own start and end time, write a function that returns the intersection of the two interval lists.

For example, the intersection of [3,8][3, 8] and [5,10][5, 10] is [5,8][5, 8].

Constraints

  • 0≤0 \leq interval_list_a.length, interval_list_b.length ≤1000\leq 1000

  • 0≤0 \leq start[i] << end[i] ≤109\leq 10^9, where ii is used to indicate interval_list_a

  • end[i] << start[i + 1]

  • 0≤0 \leq start[j] << end[j] ≤109\leq 10^9, where jj is used to indicate interval_list_b

  • end[j] << start[j + 1]

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