435. Non-overlapping Intervals¶
Edited by Charles
Medium · Python · Greedy
Problem
Read the original problem on LeetCode.
The official page contains the problem statement, examples, and constraints.
Explanation, examples & other approaches
Core idea
Recall 452. Minimum Number of Arrows to Burst Balloons to count the non-overlapping intervals. It should be noted that, in this question, the interval with start equal to some interval’s end is not counted as an overlapped interval.
Original study notes follow, including intermediate snippets and earlier attempts.
Note:
- Recall 452. Minimum Number of Arrows to Burst Balloons to count the non-overlapping intervals.
- It should be noted that, in this question, the interval with start equal to some interval’s end is not counted as an overlapped interval.
- Thus, the outcome of the solution is #intervals - #non-overlapping intervals.
Study record
| Field | Value |
|---|---|
| Attempts | 1 |
| Mastery | ❚ |
| The Latest Attempt | January 29, 2026 |
Python solution¶
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
n = len(intervals)
intervals.sort(key = lambda x: x[1])
count = 1
end = intervals[0][1]
for interval in intervals:
if interval[0] >= end:
end = interval[1]
count += 1
return n - count