intervals non-overlapping
Matrix
medium
Score: 30
Given an array of intervals such that interval[i]
= [starti, endi]
, return the minimum number of intervals needed to remove for making the remaining intervals non-overlapping.
Input Format
First Parameter - matrix intervals
of size m x n
Output Format
Return the number.
Example 1:
Input:
4 2
1 2
2 3
3 4
1 3
Output: 1
Explanation: 4 2 represents the size of the interval. 1 3 can be removed and the rest of the intervals are non-overlapping.
Example 2:
Input:
3 2
1 2
1 2
1 2
Output: 2
Explanation: 3 2 represents the size of the intervals. You need to remove two [1,2] to make the rest of the intervals
non-overlapping.
Constraints:
- 1 <= interval.length <= 105
- interval[i].length == 2
- -5 * 104 <= start[i] < end[i] <= 5 * 104
- Expected Time Complexity: O(n logn)
- Expected Auxiliary Space: O(1)