Minimum removals required to make any interval equal to the union of the given Set | Function to count minimum number of removals required to make an interval equal to the union of the given Set ; Stores the minimum number of removals ; Traverse the Set ; Left Boundary ; Right Boundary ; Stores count of intervals lying within current interval ; Traverse over all remaining intervals ; Check if interval lies within the current interval ; Increase count ; Update minimum removals required ; Driver Code ; Returns the minimum removals
def findMinDeletions ( v , n ) : NEW_LINE INDENT minDel = 10 ** 18 NEW_LINE for i in range ( n ) : NEW_LINE INDENT L = v [ i ] [ 0 ] NEW_LINE R = v [ i ] [ 1 ] NEW_LINE Count = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( v [ j ] [ 1 ] >= L and v [ j ] [ 0 ] <= R ) : NEW_LINE INDENT Count += 1 NEW_LINE DEDENT DEDENT minDel = min ( minDel , n - Count ) NEW_LINE DEDENT return minDel NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT v = [ ] NEW_LINE v . append ( [ 1 , 3 ] ) NEW_LINE v . append ( [ 4 , 12 ] ) NEW_LINE v . append ( [ 5 , 8 ] ) NEW_LINE v . append ( [ 13 , 2 ] ) NEW_LINE N = len ( v ) NEW_LINE print ( findMinDeletions ( v , N ) ) NEW_LINE DEDENT