Given a list of intervals, remove all intervals covered by another interval. An interval [a,b] is covered by [c,d] if c <= a and b <= d. Return the number of remaining intervals.
Sort by start ascending, then by end descending (so for equal starts, longer interval comes first). Keep track of the maximum end seen so far. If current end <= maxEnd, current interval is covered.
- Sort: by start asc, then end desc.
- Track maxEnd = 0, count = 0.
- For each interval: if end > maxEnd, count++, maxEnd = end (not covered).
- Return count.
- Time Complexity: O(N log N)
- Space Complexity: O(1)