Skip to content

Remove Covered Intervals

MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

An interval [a, b] is covered by [c, d] when c <= a and b <= d. Remove every interval that is covered by another interval in the list, and return how many remain.

[[1, 4], [3, 6], [2, 8]]  →  2   ([3, 6] is covered by [2, 8])
[[1, 4], [2, 3]]          →  1

Constraints

  • 1 <= intervals.length <= 1000
  • 0 <= start < end <= 10^5
  • All the intervals are unique.