Dodomeki
Sign in

160. Shared Free Windows

Hard

Each person has a schedule of occupied intervals, represented by a start and an end. An interval is interpreted as half-open: it includes its start and excludes its end.

Find the positive-length intervals during which everyone is free, considering only the period between the first commitment of anyone and the last commitment of anyone. Return the intervals as [start, end] pairs, sorted by start. If there are no commitments or no free interval within that period, return an empty list.

The intervals in each schedule are sorted by start and do not overlap. Intervals that touch do not leave a free window between them.

Example 1
Input: horarios = [[[1, 3], [6, 7]], [[2, 4]], [[2, 5], [9, 12]]]
Output: [[5, 6], [7, 9]]
Explanation: The union of the commitments leaves the windows from 5 to 6 and from 7 to 9 free.
Example 2
Input: horarios = [[[1, 2]], [], [[4, 5]]]
Output: [[2, 4]]
Explanation: The person without commitments does not change the shared window between the other two commitments.
Example 3
Input: horarios = [[[0, 2], [4, 6]], [[2, 4]]]
Output: []
Explanation: The intervals touch and together cover the entire period from 0 to 6.
Constraints
  • 1 <= horarios.length <= 10^4
  • 0 <= total number of intervals in horarios <= 10^5
  • Each interval has the form [start, end].
  • -10^9 <= start < end <= 10^9
  • Each person's intervals are sorted by start and do not overlap.
IntervalsHeapSorting
Caso 1
horarios =
[[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
Expected =
[[5,6],[7,9]]
Caso 2
horarios =
[[[1,2]],[],[[4,5]]]
Expected =
[[2,4]]
Caso 3
horarios =
[[[0,2],[4,6]],[[2,4]]]
Expected =
[]

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