Find the minimum number of intervals that need to be removed so that the remaining intervals are disjoint.
Intervals are considered disjoint if no two intervals overlap on the number line. For example:
Examples
Input: intervals = [[1,5],[2,3],[3,4],[4,6]]
Output: 1
Explanation: [1,5] overlaps with multiple intervals, and removing it makes the rest non-overlapping. Since only one interval needs to be removed, the result is 1.
Input: intervals = [[1,15],[3,5],[6,8],[8,10],[9,11]]
Output: 2
Explanation: [1,15] overlaps with all other intervals, and [9,11] overlaps with [8,10]. Removing these two intervals makes the rest non-overlapping. Since two intervals need to be removed, the result is 2.
Input: intervals = [[1,4],[4,8]]
Output: 0
Explanation: [1,4] and [4,8] are already non-overlapping, so no intervals need to be removed. Hence, the result is 0.