A list of ranges contains the start and end values continuous ranges of integers. For…
- User
A list of ranges contains the start and end values continuous ranges of integers. For example, [1, 4] denotes all integers in the range 1 to 4, or [1, 2, 3, 4]. Divide the ranges into 2 groups such that any 2 ranges that have at least one common integer belong to the same group.
Given the list of ranges, find the number of ways to distribute these ranges into 2 groups that satisfy the constraint and each group has at least one range. Since the answer can be large, compute it modulo (109+7).
Example
Consider ranges = [[1, 5], [3, 8], [10, 15], [13, 14], [20, 100]].
• [1, 5] and [3, 8] must belong to the same group since they have common integers 3, 4 and 5.
Rank Confidential
• [10, 15] and [13, 14] must belong to the same group since they have common integers 13 and 14.
• All other ranges can be distributed independently since they do not overlap.All other ranges can be distributed independently since they do not overlap.
The 6 possible groupings
Group 1
Group 2
[1, 5], [3, 8]
[10, 15], [13, 14], [20, 100]
[10, 15], [13, 14], [20, 100]
[1, 5], [3, 8]
[10, 15], [13, 14]
[1, 5], [3, 8], [20, 100]
[1, 5], [3, 8], [20, 100]
[10, 15], [13, 14]
[10, 15], [3, 8], [13, 14], [1, 5]
[20, 100]
[20, 100]
[10, 15], [3, 8], [13, 14], [1, 5]
L
A In all the distributions, each group has at least one -ange and all ranges with common integers are in he same groups. There are no other distributions possible. 6 modulo (109+7) = 6 so return 6..
unction Description
omplete the function distributeRanges in the
ditor below. distributeRanges has the following parameter: int ranges[n][2]: the ranges
Returns
int: the number of ways to distribute the ranges into 2 groups, modulo (10 ^ 9 + 7)
Constraints
• 1 <= n <= 10 ^ 5
• 0 ≤ ranges[i][j] ≤ 10^9, where 0 <= i < n, j = 0 ,1 complete function int distributeRanges (vector<vector> ranges) {
}
- Assistant