Dashboard
LC #435

Non-overlapping Intervals

Pattern · ?GoogleAmazonMeta

Problem

Find the minimum number of intervals you need to remove to make the rest non-overlapping.

Constraints

  • 1 ≤ n ≤ 10⁵
  • -5 × 10⁴ ≤ startᵢ < endᵢ ≤ 5 × 10⁴

Example

Input
intervals = [[1,2],[2,3],[3,4],[1,3]]
Output
1
Why
Remove [1,3]; remaining [1,2],[2,3],[3,4] are non-overlapping

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗