Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 924 Bytes

05_collapse.org

File metadata and controls

22 lines (18 loc) · 924 Bytes

collapse intervals

Given a collection of intervals, return the minimal collection of non-overlapping intervals that cover the same points.

Example:

[[1, 3], [5, 8], [2, 5]]  --> [[1, 5], [5, 8]]

Assume the intervals are half-open [a, b). That is, the starting element is included, the ending element is not included: [1, 4) -> [1, 2, 3]

Bonus implementation ideas:

  1. Write versions for other interval types (open-open, closed-closed, open-closed). If you have a preference, justify it.
  2. Write a data structure for a streaming version that takes one or more intervals and updates the current set of minimal intervals.
  3. Analyze the space/time complexity of your implementation.
  4. Note: I solved a very practical problem with this algorithm a few weeks ago. Demonstrate (or describe) an application of your function on a real “business” problem.