Key observation: if we have a group of pairwise overlapping intervals, we can only keep exactly one of them remaining.
But the question is which one to keep? Well, apparently, we want to keep the interval from the group with minimum end point minEnd
so it has least chance to overlap with any next coming intervals to the right. Therefore, the algorithm is straightforward:
 Sort given intervals by start points;
 For each interval, check its start point vs
minEnd
: 
 if
interval.start >= minEnd
, it means no intervals need to be removed since the current interval wouldn't overlap with any previous intervals if previous intervals in pairwise overlapping group are removed except the one with end asminEnd
;
 if

 otherwise, the current interval will become of those in the pairwise overlapping group, and we need to increment removal count by one and update
minEnd
as well.
 otherwise, the current interval will become of those in the pairwise overlapping group, and we need to increment removal count by one and update
int eraseOverlapIntervals(vector<Interval>& its) {
sort(its.begin(), its.end(), [](Interval& x, Interval& y){return x.start<y.start;});
int res = 0, minEnd = INT_MIN; // min end of pairwise overlapping group
for (auto it : its) {
if (it.start >= minEnd) minEnd = it.end; // no overlap
else ++res, minEnd = min(minEnd, it.end); // overlap and update count and minEnd
}
return res;
}