Find the minimum number of intervals to remove for no overlaps.
This problem follows the Greedy Interval Scheduling pattern, commonly found in the Intervals category. Recognizing this pattern is key to solving it efficiently in an interview setting.
Sort by end time. Greedily keep intervals that don't overlap. Count removals.
Sort by end time, not start — keeping intervals that end earliest maximizes room for future intervals. This is the classic interval scheduling greedy.
intervals.sort(key=lambda x: x[1])
count = 0
end = -infinity
for start, e in intervals:
if start >= end:
end = e # keep this interval
else:
count += 1 # remove this interval
return countPractice Non-overlapping Intervals and similar Intervals problems with flashcards. Build pattern recognition through active recall.
Practice this problem