#2406
Divide Intervals Into Minimum Number of Groups
specialist · 655 · lc medium +30 · verified · 63.6% accepted · 1,462 likes · top 66%
Description
You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the closed interval [lefti, righti].
Distribute the intervals among groups such that no two intervals in the same group overlap (sharing an endpoint counts as overlapping).
Return the minimum number of groups required.
Example 1:
Input: intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]
Output: 3
Explanation: We can divide the intervals into the following groups:
- Group 1: [1, 5], [6, 8].
- Group 2: [2, 3], [5, 10].
- Group 3: [1, 10].
It can be proven that it is not possible to divide the intervals into fewer than 3 groups.
Example 2:
Input: intervals = [[1,3],[5,6],[8,10],[11,13]]
Output: 1
Explanation: None of the intervals overlap, so we can put all of them in one group.
Code
1
2
3