Non-overlapping Intervals
Given an array of intervals, return the minimum number of intervals you must remove so that the remaining intervals do not overlap. Intervals that only touch at an endpoint are not considered overlapping.
Open official problem prompt ↗Find the fewest intervals to delete so what remains is mutually disjoint — equivalently, keep the largest possible non-overlapping subset.
Scheduling the most classes in one room: always pick the class that ends soonest so the room frees up earliest for the next one.
- Input
- intervals = [[1,2],[2,3],[3,4],[1,3]]
- Output
- 1
- Why
- Removing [1,3] leaves [1,2],[2,3],[3,4], which are all non-overlapping; no single removal fewer works.
1 <= intervals.length <= 10^5intervals[i].length == 2-5 * 10^4 <= start_i < end_i <= 5 * 10^4