← All problems

Non-overlapping Intervals

medium

Given an array of intervals [start, end], return the minimum number of intervals you'd need to remove so that none of the remaining ones overlap.

Sort by end time and greedily keep whichever interval finishes earliest — it leaves the most room for everything after it, so anything that overlaps the one you kept must be removed instead.

Example

Input: intervals = [[1, 2], [2, 3], [3, 4], [1, 3]]
Output: 1        // remove [1, 3]
Loading...