Skip to content
Onsite

Non-overlapping Intervals

MediumP2Coding

Given a list of intervals [start, end), return the minimum number of intervals to remove so that the rest do not overlap. Intervals that only touch at an endpoint (like [1,2) and [2,3)) do not overlap.

Example 1

Input
intervals = [[1,2],[2,3],[3,4],[1,3]]
Output
1
Why
Remove [1,3].

Example 2

Input
intervals = [[1,2],[1,2],[1,2]]
Output
2

Example 3

Input
intervals = [[1,2],[2,3]]
Output
0

Constraints

  • 1 <= intervals.length <= 10^5
  • -5 * 10^4 <= start < end <= 5 * 10^4

Hints

Run checks the 3 visible tests, Submit all 9.