The Remove Covered Intervals interview question gives you a list of intervals, and asks you to count how many intervals remain after removing all intervals that are completely covered by another interval in the list. An interval [a, b] is covered by [c, d] if c <= a and b <= d. The goal is to determine the number of intervals that are NOT covered by any other interval.
This interval problem is commonly asked at Meta and Amazon because it tests a candidate's ability to work with sorted intervals and apply greedy logic. It is a building block for more complex interval-related problems such as merge intervals, interval scheduling, and sweep-line algorithms. Demonstrating a clean O(n log n) solution with clear reasoning about sorting criteria shows strong algorithmic fundamentals.
The pattern is sorting plus greedy with a running maximum. Sort intervals by their start point in ascending order; for ties in start, sort by end in descending order. Then iterate through the sorted list, maintaining the maximum right endpoint seen so far (max_end). If the current interval's right endpoint is less than or equal to max_end, it is covered. Otherwise, update max_end and increment the answer counter.
Given intervals: [[1,4],[3,6],[2,8]]
Sort by start ascending, end descending: [[1,4],[2,8],[3,6]].
[1,4]: max_end is 0 → not covered → count = 1, max_end = 4.[2,8]: 8 > 4 → not covered → count = 2, max_end = 8.[3,6]: 6 ≤ 8 → covered → skip.Result: 2 intervals remain.
For the Remove Covered Intervals coding problem, practice the sorting criterion carefully: ascending start, descending end. Walking through a small example before coding will help you verify your sort order. Interviewers at Meta and Amazon look for candidates who can justify why the secondary sort on end descending is necessary — being able to explain this clearly demonstrates depth of understanding of the array and sorting interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Maximal Uncovered Ranges | Medium | Solve | |
| Maximum Consecutive Floors Without Special Floors | Medium | Solve | |
| Sort the Jumbled Numbers | Medium | Solve | |
| Check if Grid can be Cut into Sections | Medium | Solve | |
| Count Days Without Meetings | Medium | Solve |