120. Non-overlapping Intervals
Medium · Array
Given a list of intervals represented as [start, end] pairs, find the minimum number of intervals you must remove to make the remaining intervals non-overlapping. Two intervals [a, b] and [c, d] are considered overlapping if they share any point in common (i.e., they overlap if not (b < c or d < a)).
Return the minimum count of intervals to remove so that no two remaining intervals overlap.
Examples
Example 1 Input: [[1, 2], [2, 3]] Output: 0 Explanation: The intervals [1, 2] and [2, 3] do not overlap (they only touch at point 2), so no removal is needed.
Example 2 Input: [[1, 2], [1, 2], [1, 2]] Output: 2 Explanation: All three intervals are identical and completely overlap. We must remove 2 of them, keeping only 1.
Constraints
- Standard input/output constraints apply