Skip to content
BASA DSA

Non Overlapping Intervals

MediumIntervals

Return the fewest intervals to remove so that remaining intervals do not overlap. Touching endpoints are allowed.

Example 1

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

Explanation

Remove [2,4] and keep [1,3],[3,5]; touching at 3 is allowed.

Example 2

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

Explanation

The intervals merely touch at 2, so no removal is needed.

Example 3

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

Explanation

Only one identical interval may remain, requiring two removals.

Constraints

  • 1 <= number of intervals <= 100000
  • Each interval has start < end

Function contracteraseOverlapIntervalsArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…