How to remove overlapping intervals in Python

🔷 Day 22- 30DaysChallenge(Leetcode Problem): Non-overlapping Intervals 🌟 Problem: Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note that intervals which only touch at a point are non-overlapping. For example, [1, 2] and [2, 3] are non-overlapping. 🧠Solution: class Solution:   def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:     intervals.sort()     count = 0     for i in range(1, len(intervals)):       if intervals[i][0] < intervals[i-1][1]:         if intervals[i][1] < intervals[i-1][1]:           intervals[i-1] = intervals[i]         else:           intervals[i] = intervals[i-1]         count += 1     return count #DSA #Python #CodingChallenge #30dayschallenge #Leetcode

To view or add a comment, sign in

Explore content categories