#435
Non-overlapping Intervals
medium· Intervalsruns: 0Given an array of intervals where intervals[i] = [start_i, end_i], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 364
class Solution:
def eraseOverlapIntervals(
self, intervals: list[list[int]]
) -> int:
intervals.sort(key=lambda x: x[1])
count = 0
prev_end = float("-inf")
for start, end in intervals:
if start >= prev_end:
prev_end = end
else:
count += 1
return count
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.