← 返回 uber 的题目列表Active Couriers Timeline
类型:qbank
Given a set of courier working intervals [start, end) that may overlap, return the timeline broken into segments [segmentStart, segmentEnd, activeCount], creating a new segment only when the number of active couriers changes and emitting only segments where the active count is positive.
Active Couriers Timeline
Given a set of courier working intervals [start, end) that may overlap, return the timeline broken into segments [segmentStart, segmentEnd, activeCount], creating a new segment only when the number of active couriers changes and emitting only segments where the active count is positive.
SWE
interval
interval-aggregation
sorting
medium
Frequency
Single report
Last asked
2026-03-23
Stage
onsite-coding
Active Couriers Timeline
You are given couriers, where couriers[i] = [start, end] represents the working interval of the ith courier. start is inclusive and end is exclusive.
Intervals may overlap. Return a list of timeline segments [segmentStart, segmentEnd, activeCount] such that:
activeCount is the number of couriers working throughout the entire segment.
You only create a new segment when the number of active couriers changes.
Only segments with activeCount > 0 should appear in the output.
If multiple couriers start or end at the same time, treat all changes at that timestamp together before moving to the next segment.
Examples
Example 1:
Input: couriers = [[1,5],[3,7]]
Output: [[1,3,1],[3,5,2],[5,7,1]]
Explanation:
From 1 to 3, one courier is active. From 3 to 5, both are active. From 5 to 7, only the second courier remains.
Example 2:
Input: couriers = [[1,3],[3,5],[3,6]]
Output: [[1,3,1],[3,5,2],[5,6,1]]
Explanation:
Because intervals are [start, end), the courier ending at 3 is not active at time 3, while the two couriers starting at 3 are.
Constraints
1 <= couriers.length <= 10^5
couriers[i].length == 2
0 <= start < end <= 10^9