Skip to content

Practice Count Ways to Group Overlapping Ranges

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2580
LeetCode Problem

Count Ways to Group Overlapping Ranges

Problem Statement

Each ranges entry [start,end] includes both endpoints. Assign every range to one of two distinct groups, either of which may be empty, such that ranges sharing at least one integer always belong to the same group. Return the number of valid assignments modulo 10^9 + 7.

Source: Count Ways to Group Overlapping Ranges on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
ranges = [[6,10],[5,15]]
Output
2

# Example 2

Input
ranges = [[1,3],[10,20],[2,5],[4,8]]
Output
4

Constraints

1 <= ranges.length <= 10^5
ranges[i].length == 2
0 <= starti <= endi <= 10^9

Related LeetCode Problems

Practice more problems similar to Count Ways to Group Overlapping Ranges.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.