Remove Covered Intervals - Problem
Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.
An interval [a, b) is covered by interval [c, d) if and only if c ≤ a and b ≤ d.
Return the number of remaining intervals after removing all covered intervals.
Input & Output
Example 1 — Basic Coverage
$
Input:
intervals = [[1,4],[3,6],[2,8]]
›
Output:
2
💡 Note:
Interval [3,6] is covered by [2,8] because 2 ≤ 3 and 6 ≤ 8. So [1,4] and [2,8] remain.
Example 2 — No Coverage
$
Input:
intervals = [[1,4],[2,3]]
›
Output:
1
💡 Note:
Interval [2,3] is covered by [1,4] because 1 ≤ 2 and 3 ≤ 4. Only [1,4] remains.
Example 3 — Multiple Covered
$
Input:
intervals = [[1,2],[1,4],[3,4]]
›
Output:
1
💡 Note:
[1,4] covers both [1,2] and [3,4]. Only [1,4] remains.
Constraints
- 1 ≤ intervals.length ≤ 1000
- intervals[i].length == 2
- 0 ≤ li < ri ≤ 105
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code