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
function findMinDeletions ( v , n ) { let minDel = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let L = v [ i ] [ 0 ] ; let R = v [ i ] [ 1 ] ; let Count = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( v [ j ] [ 0 ] >= L && v [ j ] [ 1 ] <= R ) { Count += 1 ; } } minDel = Math . min ( minDel , n - Count ) ; } return minDel ; } let v = [ [ 1 , 3 ] , [ 4 , 12 ] , [ 5 , 8 ] , [ 13 , 20 ] ] ; let N = v . length ; document . write ( findMinDeletions ( v , N ) ) ;