Minimum removals required to make ranges non |  ; Sort by minimum starting point ; If the current starting point is less than the previous interval 's ending  point (ie. there is an overlap) ; Increase rem ; Remove the interval with the higher ending point ; Driver Code
def minRemovels ( ranges ) : NEW_LINE INDENT size = len ( ranges ) NEW_LINE rem = 0 NEW_LINE ranges . sort ( ) NEW_LINE end = ranges [ 0 ] [ 1 ] NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT if ( ranges [ i ] [ 0 ] < end ) : NEW_LINE INDENT rem += 1 NEW_LINE end = min ( ranges [ i ] [ 1 ] , end ) NEW_LINE DEDENT else : NEW_LINE INDENT end = ranges [ i ] [ 1 ] NEW_LINE DEDENT DEDENT return rem NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT Input = [ [ 19 , 25 ] , [ 10 , 20 ] , [ 16 , 20 ] ] NEW_LINE print ( minRemovels ( Input ) ) NEW_LINE DEDENT