Atlassian 面试题:查找重叠 Pipeline 区间(Find Overlapping Pipeline Intervals)

57次阅读
没有评论

Problem – Find Overlapping Pipeline Intervals

Find all time intervals during which at least two pipelines are running at the same time.

You are given a list of half-open or closed intervals (assume closed here) where each interval
[start, end] represents the running time of one pipeline.

Return all sub-intervals where the number of running pipelines is ≥ 2.

Example

Input:
[[2, 5], [12, 15], [4, 8]]

Output:
[[4, 5]]

Because between time 4 and 5, both the interval [2, 5] and [4, 8] are running.


思路总结(Brief Idea)

  • 把每个区间拆成两个“事件”:(start, +1)(end, -1)
  • 按时间排序(同一时间先处理 +1 再处理 -1)。
  • 从左到右扫一遍,用 running 记录当前运行中的 pipeline 数。
    • running 从 1 变成 2 时,记录重叠区间的开始时间。
    • running 从 2 变成 1 时,记录结束时间并加入结果。
  • 时间复杂度:排序 O(n log n),扫描 O(n)。

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Meta、Google、Amazon 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Stripe 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0