← 返回 snowflake 的题目列表Handle Intervals When Input Is Not Sorted
类型:online_judge
Problem: Interval Processing — Input Is Not Guaranteed to Be Sorted
You are given a list of intervals intervals, where each interval is [l, r] with l <= r.
Interval A = [l1, r1] is covered by interval B = [l2, r2] if l2 <= l1 and r1 <= r2.
Given that the input is not sorted by start, remove all intervals that are covered by another interval and return the number of remaining intervals.
Input
n intervals: 1 <= n <= 2 * 10^5
Endpoints: 0 <= l <= r <= 10^9
Output
The number of intervals remaining after removing covered intervals.
Examples
[[1,4],[3,6],[2,8]] -> 2
[[1,4],[2,3]] -> 1
[[0,10],[5,12]] -> 2
[[1,2],[1,4],[3,4]] -> 1
[[1,1],[1,2],[2,2],[0,3]] -> 1
Example
Input
[[1,4],[3,6],[2,8]]
Output
2