# Leetcode 435 - Non-overlapping intervals

`Note:`

- How to be greedy?
- Local optima: If the curernt interval overlaps with prev intervals, removing only it def costs less than removing some prev intervals.
- Global optima: Min deleltions.

- Much like the
`balloons`

problem:`Sorting`

by`end`

first makes it easier.- If the current interval doesnâ€™t overlap with prev intervals, join them all as a new bigger interval.
- If the current interval overlaps with prev intervals, delete the current one only!

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.

**Exmaple**

1 | Input: intervals = [[1,2],[2,3],[3,4],[1,3]] |

1 | /** |