You are given n time intervals representing debug log segments. Each interval has a start time, an end time, and an associated text message.
(start, end, text)
.
start
and
end
are integers representing timestamps in seconds.
[start, end)
, i.e., they include
start
and exclude
end
.
Write a function that:
[(start_i, end_i, text_i)]
.
[min_start, max_end)
where:
min_start
is the smallest start time among those intervals.
max_end
is the largest end time among those intervals.
(start, end, merged_text)
.
Example (one possible style of input/output):
[(0, 5, "A"), (3, 10, "B"), (12, 15, "C")]
[(0, 10, "A B"), (12, 15, "C")]
(You can assume that the concatenation order for texts is determined by the start time of each interval; if start times are equal, you may break ties arbitrarily.)
Using the same input model (original, unmerged intervals):
[s1, e1)
and
[s2, e2)
overlap if their intersection is non-empty, i.e.,
max(s1, s2) < min(e1, e2)
.
next.start > current.end
.
Define and implement appropriate functions/methods to:
State the expected time and space complexity of your approach in terms of n (the number of intervals).