Divide Intervals Into Minimum Number of Groups
Given a 2D array intervals where intervals[i] = [left_i, right_i] is an inclusive interval, divide all intervals into groups so that no two intervals in the same group intersect (share any common number). Return the minimum number of groups needed. Two intervals intersect if they overlap at even a single point, e.g. [1,5] and [5,8] intersect because they share 5.
Open official problem prompt ↗Find the fewest groups so that within each group the intervals are pairwise disjoint — equivalently, find the maximum number of intervals that are simultaneously active at any point.
Think of meeting rooms: each interval is a meeting, and two meetings clashing at any instant need separate rooms. The number of rooms you must book is the greatest number of meetings running at the same moment.
- Input
- intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]
- Output
- 3
- Why
- At point 5, the intervals [5,10], [1,5], and [1,10] all overlap, so at least 3 groups are required and 3 suffice.
1 <= intervals.length <= 10^5intervals[i].length == 21 <= left_i <= right_i <= 10^6