Count Ways to Group Overlapping Ranges
You are given a 2D integer array ranges where ranges[i] = [starti, endi] denotes that all integers between starti and endi (both inclusive) are contained in the i^th range.
You are to split ranges into two possibly empty groups such that:
- Each range belongs to exactly one group.
- Any two overlapping ranges must belong to the same group.
Two ranges are said to be overlapping if there exists at least one integer that is present in both ranges.
Return the total number of ways to split ranges into two groups. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1
Input
ranges = [[6,10],[5,15]]Output
2The two ranges overlap, so they must stay together, and that combined component can be placed in either group.
Example 2
Input
ranges = [[1,3],[10,20],[2,5],[4,8]]Output
4The ranges [1,3], [2,5], and [4,8] form one overlapping component, while [10,20] is separate, giving four group assignments.
Constraints
- 1 <= ranges.length <= 10^5
- ranges[i].length == 2
- 0 <= starti <= endi <= 10^9