Loading...
Loading...
You are given a list of strings labels and a list of intervals intervals of the same length. Each intervals[i] = [start, end] means that labels[i] is active at every time t with start <= t < end. The same label can appear more than once in labels.
At any time, some set of labels is active. Cut the timeline at every time where this set changes. Each piece where the set is not empty is a segment [s, e). Times where no label is active belong to no segment.
Return the segments ordered by start time. Write each segment as one string: s, then e, then the labels active during the segment, all separated by single spaces. List each active label once, in lexicographic order.
Note that a label is active as long as at least one of its intervals covers the time. If one of its intervals ends while another of its intervals still covers that time, the set does not change there.
You can assume the returned segments list at most 2 * 10^5 labels in total.
Input: labels = ["Mary", "John", "Peter", "Crystal", "Jane"]
intervals = [[ 10, 40],
[ 30, 50],
[ 50, 80],
[100, 150],
[120, 180]]
Output: ["10 30 Mary", "30 40 John Mary", "40 50 John", "50 80 Peter", "100 120 Crystal", "120 150 Crystal Jane", "150 180 Jane"]
Explanation: Mary is active alone from 10 to 30. John joins at 30, and Mary leaves at 40.
At 50, John leaves and Peter joins, so the set changes from {John} to {Peter}.
No label is active from 80 to 100, so that range is not a segment.
Input: labels = ["Ana", "Ben", "Ana"]
intervals = [[ 0, 10],
[ 5, 15],
[10, 20]]
Output: ["0 5 Ana", "5 15 Ana Ben", "15 20 Ana"]
Explanation: At time 10, the first interval of Ana ends and the second one begins.
Ana stays active, so the set {Ana, Ben} does not change and the segment from 5 runs on to 15.
Input: labels = ["Kai", "Kai", "Lee"]
intervals = [[ 1, 9],
[ 3, 5],
[12, 14]]
Output: ["1 9 Kai", "12 14 Lee"]
Explanation: Kai's interval [3, 5) lies inside [1, 9), so Kai is active from 1 to 9 and the set never changes in between.
Nothing is active from 9 to 12.
labels.length ≤105intervals.length == labels.lengthstart < end ≤109 for each [start, end] in intervals