Non-overlapping Intervals
Last updated
Last updated
Given a list of intervals, find the minimum number of intervals that you need to removed to make the rest of the intervals non-overlapping.
Finding minimum is an optimization question so likely to be DP or greedy.
has a later end time (optimality)
Time O(nlogn) + O(n)
Space O(n)
This is actually a classic problem in interval scheduling. An equivalent problem statement is to find the maximum number of intervals that are non-overlapping.
We can assume there is an optimal solution such as by removing a set of intervals .
By exchange argument, we can swap out an interval from the removing set with an interval that
overlaps with (correctness)
We can keep an interval in the list if does not overlap from before (correctness).
For example, we have an optimal removing set . We can swap with to guarantee optimality because overlaps and ends at a later time. Again, we can swap with with the same reason. Now we have with a new removing set that is also optimal. Because we start this exchange process with a greedy choice, this greedy algorithm is proved to be optimal by induction.
Wikipedia -
Algorithm Design -