84. Non-overlapping Intervals

Return the minimum number of intervals to remove so the rest do not overlap. Intervals that only touch (like [1,2] and [2,3]) do not overlap.

Example 1

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

Example 2

Input: intervals = [[1,2],[1,2],[1,2]]
Output: 2
Hint 1

Keeping the interval that ends earliest leaves the most room for the rest.

Hint 2

This is the classic activity-selection greedy.

GreedyIntervalsSorting