Remove Covered Intervals
MediumIntervalsgreedy
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a list of distinct intervals, where intervals[i] = [l_i, r_i]. Interval [a, b] is *covered* by interval [c, d] when c <= a and b <= d (and the two intervals are different entries).
Remove every interval that is covered by some other interval in the list, and return how many intervals remain.
Examples
Input: intervals = [[1,4],[3,6],[2,8]]
Output: 2
`[3,6]` lies inside `[2,8]`, so it is removed.
Input: intervals = [[1,4],[2,3]]
Output: 1
`[2,3]` lies inside `[1,4]`.
Constraints
- 1 <= intervals.length <= 1000
- intervals[i].length == 2
- 0 <= l_i < r_i <= 10^5
- All intervals are distinct
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.