Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

1288 - Remove Covered Intervals #273

@anuranjanpandey

Description

@anuranjanpandey

Description of the Problem

Given a list of intervals, remove all intervals that are covered by another interval in the list.

Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.

After doing so, return the number of remaining intervals.

Code

class Solution:
    def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
        intervals.sort(key = lambda x: (x[0], -x[1]))
        inside = 0
        right = -1
        for i, j in intervals:
            if j <= right:
                inside += 1
            else:
                right = j
        return len(intervals) - inside

Link To The LeetCode Problem

LeetCode

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions