Non-overlapping Intervals

Medium

Description

Given an array of intervals where intervals[i] = [start, end], return the minimum number of intervals you need to remove to make the rest non-overlapping.

Examples

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

Remove [1,3] to make the rest non-overlapping.

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

Remove two [1,2] intervals.

Input:intervals = [[1,2],[2,3]]
Output:0
Explanation:

Edge case returning zero.

Constraints

  • 1 ≤ intervals.length ≤ 10⁵
  • intervals[i].length == 2

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!