Minimum Circles needed to be removed so that all remaining circles are non intersecting | Function to return the count of non intersecting circles ; Structure with start and end of diameter of circles ; Sorting with smallest finish time first ; count stores number of circles to be removed ; cur stores ending of first circle ; Non intersecting circles ; Intersecting circles ; Centers of circles ; Radius of circles ; Number of circles
def CountCircles ( c , r , n ) : NEW_LINE INDENT diameter = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT obj = [ ] NEW_LINE obj . append ( c [ i ] - r [ i ] ) NEW_LINE obj . append ( c [ i ] + r [ i ] ) NEW_LINE diameter . append ( obj ) NEW_LINE DEDENT diameter . sort ( ) NEW_LINE count = 0 NEW_LINE cur = diameter [ 0 ] [ 1 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( diameter [ i ] [ 0 ] > cur ) : NEW_LINE INDENT cur = diameter [ i ] [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE DEDENT c = [ 1 , 2 , 3 , 4 ] NEW_LINE r = [ 1 , 1 , 1 , 1 ] NEW_LINE n = len ( c ) NEW_LINE CountCircles ( c , r , n ) NEW_LINE