Given N intervals, each starting at s[i] and ending at e[i]. We need to select the largest set of possible intervals that are non-overlapping.
The optimal algorithm is sort by ending time, then always select the interval with the earliest e[i] at each step.
But another strategy is the following: at each step, for each interval, compute the number of intervals it overlaps it. Then select the one that overlaps with the least number of intervals.
Is the second algorithm optimal? I'm trying to find a counter-example, but haven't found it yet.
Counter-Example:
[----][----][----][----]
[----][----][----]
[----] [----]
[----] [----]