Remove Covered Intervals

Try to solve the Remove Covered Intervals problem.

Statement

Given an array of intervals, where each interval is represented as intervals[i] =[li,ri)= [l_i, r_i) (indicating the range from lil_i to rir_i, inclusive of lil_i and exclusive of rir_i), remove all intervals that are completely covered by another interval in the list. Return the count of intervals that remain after removing the covered ones.

Note: An interval [a,b)[a, b) is considered covered by another interval [c,d)[c, d) if and only if c<=ac <= a and b<=db <= d.

Constraints:

  • 1<=1 <= intervals.length <=1000<= 1000

  • intervals[i].length ==2== 2

  • 0<=li<ri<=1050 <= l_i < r_i <= 10^5

  • All the given intervals are unique.

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.