LeetCode 435 Non-overlapping Intervals - Problem Statement

The problem

Given an array of intervals, find the minimum number of intervals to remove to make the rest non-overlapping.

With intervals = [[1,2],[2,3],[3,4],[1,3]]:

  • [1,3] overlaps with [1,2] and [2,3].
  • Remove [1,3]. Remaining: [[1,2],[2,3],[3,4]]. No overlaps.
  • Remove 11 interval.

With intervals = [[1,2],[1,2],[1,2]]:

  • All identical. Keep one, remove two.
  • Remove 22 intervals.

With intervals = [[1,2],[2,3]]:

  • [1,2] ends at 2, [2,3] starts at 2. No overlap (endpoints touching is OK).
  • Remove 00 intervals.

Constraints: 11 \le intervals.length 105\le 10^5.