java.lang.Object
g2401_2500.s2406_divide_intervals_into_minimum_number_of_groups.Solution

public class Solution extends Object
2406 - Divide Intervals Into Minimum Number of Groups.<p>Medium</p> <p>You are given a 2D integer array <code>intervals</code> where <code>intervals[i] = [left<sub>i</sub>, right<sub>i</sub>]</code> represents the <strong>inclusive</strong> interval <code>[left<sub>i</sub>, right<sub>i</sub>]</code>.</p> <p>You have to divide the intervals into one or more <strong>groups</strong> such that each interval is in <strong>exactly</strong> one group, and no two intervals that are in the same group <strong>intersect</strong> each other.</p> <p>Return <em>the <strong>minimum</strong> number of groups you need to make</em>.</p> <p>Two intervals <strong>intersect</strong> if there is at least one common number between them. For example, the intervals <code>[1, 5]</code> and <code>[5, 8]</code> intersect.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> We can divide the intervals into the following groups:</p> <ul> <li> <p>Group 1: [1, 5], [6, 8].</p> </li> <li> <p>Group 2: [2, 3], [5, 10].</p> </li> <li> <p>Group 3: [1, 10].</p> </li> </ul> <p>It can be proven that it is not possible to divide the intervals into fewer than 3 groups.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> intervals = [[1,3],[5,6],[8,10],[11,13]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> None of the intervals overlap, so we can put all of them in one group.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= intervals.length <= 10<sup>5</sup></code></li> <li><code>intervals[i].length == 2</code></li> <li><code>1 <= left<sub>i</sub> <= right<sub>i</sub> <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minGroups

      public int minGroups(int[][] intervals)