Dodomeki
Sign in

122. Shared Scheduling Windows

Medium

Two schedules are represented by lists of closed intervals. Within each list, the intervals are sorted by start and do not overlap.

Each interval is a pair [start, end], with start <= end. Find every interval that belongs to both schedules. Return each intersection as [start, end], in increasing order of start. Because the intervals are closed, two intervals that share only one point produce an intersection containing that single point.

Example 1
Input: agenda_a = [[1, 4], [8, 12]], agenda_b = [[2, 6], [9, 10]]
Output: [[2, 4], [9, 10]]
Explanation: The schedules overlap from 2 to 4 and from 9 to 10.
Example 2
Input: agenda_a = [[-3, 1], [5, 7]], agenda_b = [[1, 4], [6, 9]]
Output: [[1, 1], [6, 7]]
Explanation: The first pair shares only the point 1.
Example 3
Input: agenda_a = [[2, 3]], agenda_b = [[5, 8]]
Output: []
Constraints
  • 0 <= agenda_a.length, agenda_b.length <= 10^4
  • agenda_a[i].length == agenda_b[j].length == 2
  • agenda_a[i][0] <= agenda_a[i][1] and agenda_b[j][0] <= agenda_b[j][1]
  • Intervals within each schedule are sorted by start and do not overlap; endpoints are integers between -10^9 and 10^9.
IntervalsTwo pointers
Caso 1
agenda_a =
[[1,4],[8,12]]
agenda_b =
[[2,6],[9,10]]
Expected =
[[2,4],[9,10]]
Caso 2
agenda_a =
[[-3,1],[5,7]]
agenda_b =
[[1,4],[6,9]]
Expected =
[[1,1],[6,7]]
Caso 3
agenda_a =
[[2,3]]
agenda_b =
[[5,8]]
Expected =
[]

Run checks these 3 cases. Submit runs all 12, including hidden ones.