Non-overlapping Intervals
Given an array of intervals where each interval is [start, end], return the minimum number of intervals to remove so that the remaining intervals do not…
Given an array of intervals where each interval is [start, end], return the minimum number of intervals to remove so that the remaining intervals do not overlap. Intervals that touch at an endpoint are non-overlapping: [1,3] and [3,4] may both remain.
- 1 <= intervals.length <= 100000 - intervals[i].length == 2 - 0 <= start < end <= 100000 - The semantic teaching trace accepts at most 8 intervals; coding retains the complete bounds above.
Example 1: input intervals = [[1,2],[2,3],[3,4],[1,3]]; output 1. Remove [1,3]; the other intervals touch only at endpoints and can all remain.
Example 2: input intervals = [[1,3],[1,4],[3,5],[3,4],[4,5]]; output 2. Remove [1,4] and [3,5]; three intervals remain without overlap.
Category: Greedy Algorithms. Topic: greedy. Difficulty: Medium. Patterns: greedy, sorting.