Intersect Multiple Interval Lists
Problem statement
You are given intervalLists, an array of lists of closed integer intervals. An interval [start, end] includes both endpoints. A list may be unsorted and may contain overlapping intervals.
First normalize every list by sorting and merging its overlapping intervals. Then return all maximal nonempty closed intervals that occur in every normalized list, sorted by start.
Examples
Example 1
intervalLists = [[[0,2],[5,10],[13,23]],[[1,5],[8,12],[15,24]]]return = [[1,2],[5,5],[8,10],[15,23]]The result contains every closed overlap shared by the two lists, including the single-point interval [5,5].
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.