Skip to content
Decoder

Remove Covered Intervals

Medium

Problem

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.

Example 1

Input
[[1, 4], [3, 6], [2, 8]]
Output
2
Why
[3, 6] is covered by [2, 8]

Example 2

Input
[[1, 4], [2, 3]]
Output
1

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.