Return the minimum number of intervals to remove so the remaining intervals do not overlap. Touching at an endpoint is fine.
Keep the interval that finishes earliest. It leaves the most room for the rest. Any interval starting before the last kept end must be removed.
1function eraseOverlapIntervals(intervals: number[][]): number {2intervals.sort((a, b) => a[1] - b[1]);3let end = -Infinity, removed = 0;4for (const [s, e] of intervals) {5if (s >= end) end = e;6else removed++;7}8return removed;9}
Sort by end time.
Space: play/pause · ←/→: step