1222. Remove Covered Intervals
My accepted C++ solution to LeetCode problem 1222, Remove Covered Intervals, running in 0ms.
- Difficulty: Medium
- C++
- Runtime 0ms
- Memory 15.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 15.1MB, accepted 2025-12-27.
class Solution {
public:
int removeCoveredIntervals(vector<vector<int>>& intervals) {
sort(intervals.begin(), intervals.end(), [](auto& a, auto& b) {
return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0];
});
int count = 0, maxEnd = 0;
for (auto& i : intervals) {
if (i[1] > maxEnd) { count++; maxEnd = i[1]; }
}
return count;
}
};