Non-overlapping Intervals

Greedy & Intervals, problem 6 of 8

Non-overlapping Intervals

Medium

LC #435

intervalsgreedysorting

Not attempted yet

Given intervals where each is [start, end], return the minimum number of intervals to remove so that the remaining ones don't overlap.

Intervals that only touch, like [1,2] and [2,3], do not overlap.

Example 1

Input: intervals = [[1,2],[2,3],[3,4],[1,3]]
Output: 1

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
  • -10^5 <= start < end <= 10^5

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.