LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 15.1MB, accepted 2025-12-27.

cpp
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;
    }
};

Source