class Solution {
public:
int minGroups(vector<vector<int>>& intervals) {
sort(intervals.begin(), intervals.end());
// Build a small-root heap, maintain the smallest right top
priority_queue<int, vector<int>, greater<int>> q;
for (auto& i : intervals) {
if (!q.empty() && i[0] > q.top()) {
q.pop();
}
q.push(i[1]);
}
return q.size();
}
};