Junior — Senior
Determining the minimum number of segments to remove
livecode
Task condition
It is necessary to implement a function that calculates the minimum number of segments to remove from the list so that all remaining segments do not intersect.
/*
Example 1:
Input: segments = [[1,2],[2,3],[3,4],[1,3]]
Output: 1
Explanation: Removing the segment [1,3] is enough, after which the remaining segments do not intersect.
Example 2:
Input: segments = [[1,2],[1,2],[1,2]]
Output: 2
Explanation: You need to remove two segments [1,2] so that the remaining segment has no conflicts.
Example 3:
Input: segments = [[1,2],[2,3]]
Output: 0
Explanation: No need to remove anything, the segments do not intersect already.
*/
int minRemovals(vector<vector<int>>& segs) {
}