Maximum number of parallelograms that can be made using the given length of line segments | Function to find the maximum number of parallelograms can be made ; Finding the length of the frequency array ; Increasing the occurrence of each segment ; To store the count of parallelograms ; Counting parallelograms that can be made using 4 similar sides ; counting segments which have occurrence left >= 2 ; Adding parallelograms that can be made using 2 similar sides ; Driver code
def convert ( n , a ) : NEW_LINE INDENT z = max ( a ) + 1 NEW_LINE ff = [ 0 ] * z NEW_LINE for i in range ( n ) : NEW_LINE INDENT ff [ a [ i ] ] += 1 NEW_LINE DEDENT cc = 0 NEW_LINE for i in range ( z ) : NEW_LINE INDENT cc += ff [ i ] // 4 NEW_LINE ff [ i ] = ff [ i ] % 4 NEW_LINE DEDENT vv = 0 NEW_LINE for i in range ( z ) : NEW_LINE INDENT if ( ff [ i ] >= 2 ) : NEW_LINE INDENT vv += 1 NEW_LINE DEDENT DEDENT cc += vv // 2 NEW_LINE print ( cc ) NEW_LINE DEDENT n = 4 NEW_LINE a = [ 1 , 2 , 1 , 2 ] NEW_LINE convert ( n , a ) NEW_LINE