435. Non-overlapping Intervals
[Medium] “Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set), withotu duplicate subsets."
Python3:
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
end = float('-inf')
count = 0
# sort by end time
sorted_intervals = sorted(intervals, key=lambda x: x[1])
for interval in sorted_intervals:
# check if interval is not overlapping and shift window
if interval[0] >= end:
end = interval[1]
else:
count += 1
return count