2406. Divide Intervals Into Minimum Number of Groups Medium
1/**
2 * [2406] Divide Intervals Into Minimum Number of Groups
3 *
4 * You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].
5 * You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.
6 * Return the minimum number of groups you need to make.
7 * Two intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.
8 *
9 * Example 1:
10 *
11 * Input: intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]
12 * Output: 3
13 * Explanation: We can divide the intervals into the following groups:
14 * - Group 1: [1, 5], [6, 8].
15 * - Group 2: [2, 3], [5, 10].
16 * - Group 3: [1, 10].
17 * It can be proven that it is not possible to divide the intervals into fewer than 3 groups.
18 *
19 * Example 2:
20 *
21 * Input: intervals = [[1,3],[5,6],[8,10],[11,13]]
22 * Output: 1
23 * Explanation: None of the intervals overlap, so we can put all of them in one group.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= intervals.length <= 10^5
29 * intervals[i].length == 2
30 * 1 <= lefti <= righti <= 10^6
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/
36// discuss: https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn min_groups(intervals: Vec<Vec<i32>>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2406() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.