Problem
Split ranges into two groups (either group may be empty) so that any two ranges that overlap end up in the same group. Ranges are inclusive, so [1, 3] and [3, 5] overlap because they share 3. Return the number of ways to split them, modulo 10^9 + 7.
Example 1
- Input
- [[6, 10], [5, 15]]
- Output
- 2
Example 2
- Input
- [[1, 3], [10, 20], [2, 5], [4, 8]]
- Output
- 4
In the second example, [1, 3], [2, 5] and [4, 8] are chained together and must share a group, and [10, 20] is on its own. Two independent blocks give 2 · 2 = 4 ways.
Constraints
1 <= ranges.length <= 10^50 <= start <= end <= 10^9