<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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]
<strong>Output:</strong> 3
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> intervals = [[1,3],[5,6],[8,10],[11,13]]
<strong>Output:</strong> 1
<strong>Explanation:</strong> None of the intervals overlap, so we can put all of them in one group.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= intervals.length &lt;= 10<sup>5</sup></code></li>
	<li><code>intervals[i].length == 2</code></li>
	<li><code>1 &lt;= left<sub>i</sub> &lt;= right<sub>i</sub> &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def minGroups(self, intervals: List[List[int]]) -> int:
        pq = []
        for left, right in sorted(intervals):
            if pq and pq[0] < left:
                heappop(pq) #min heap
            heappush(pq, right) 
        return len(pq)
        
        '''
        think of this as a train arrival and departure problem where we need to find min no of platforms required for all trains to arrive and depart.
no see in this example nums[] = [[5,10],[6,8],[1,5],[2,3],[1,10]] , nums[0] is arrival time and nums[1] is departure time ,
sort this array hence we have increasing arrival times (read whole u will understand)
after sort we get this -> [(1 , 5) , (1 , 10) , (2, 3) , (5, 10) , (6,8)]
heap -[]
now the first train comes and we put this on a platform 1 -> heap[5]
the second train comes and checks whether is there any train which leaves before I come(this is the main reason for keeping min heap) for this we see the top of the heap and if the top < this trains arrival time then no need for new platform else we will need a new one.
now in the second case train comes at 1 and the top of the heap is 5 which means we have to put this on another platform 2 and insert 10 in heap -> heap[5, 10]
in the third same happens train comes at 2 and checks whether any train is leaving before 2 so it can go on that platform but it's a no since heap.top() > nums[i][0] so put its departure in heap->heap[3 , 5 , 10] and this comes on platform 3
fourth trains come and checks now here this comes at 5 and heap.top() is 3 which means a train is leaving at 3 so this train will come on that platform and we will update new timing
hence heap.pop() and insert new departure time [5 , 10 , 10]
same for fifth ,my train arrives at 6 but at one of the platforms a train is leaving at 5 only so this train can go there hence no need for the new platform. so update the heap
heap.pop() and push current departure time heap->[6 , 10 , 10]
hence my final answer is a heap.size()
I hope you understand this I am not good at writing(and English as well) and this is my first explanation.
        '''


        
1128