text: Divide array in two maximum equal length arrays of similar and dissimilar elements | Function to find the max - size to which an array can be divided into 2 equal parts ; Vector to find the frequency of each element of list ; Find the maximum frequency element present in list arr ; Find total unique elements present in list arr ; Find the Max - Size to which an array arr [ ] can be splitted ; Find the first array containing same elements ; Find the second array containing unique elements ; Driver code ; Initialise n ; Array declaration ; Size of array
code: def Solve ( arr , size , n ) : NEW_LINE INDENT v = [ 0 ] * ( n + 1 ) ; NEW_LINE for i in range ( size ) : NEW_LINE INDENT v [ arr [ i ] ] += 1 NEW_LINE DEDENT max1 = max ( set ( arr ) , key = v . count ) NEW_LINE diff1 = n + 1 - v . count ( 0 ) NEW_LINE max_size = max ( min ( v [ max1 ] - 1 , diff1 ) , min ( v [ max1 ] , diff1 - 1 ) ) NEW_LINE print ( " Maximum ▁ size ▁ is ▁ : " , max_size ) NEW_LINE print ( " The ▁ First ▁ Array ▁ Is ▁ : ▁ " ) NEW_LINE for i in range ( max_size ) : NEW_LINE INDENT print ( max1 , end = " ▁ " ) NEW_LINE v [ max1 ] -= 1 NEW_LINE DEDENT print ( ) NEW_LINE print ( " The ▁ Second ▁ Array ▁ Is ▁ : ▁ " ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT if ( v [ i ] > 0 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE max_size -= 1 NEW_LINE DEDENT if ( max_size < 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 7 NEW_LINE arr = [ 1 , 2 , 1 , 5 , 1 , 6 , 7 , 2 ] NEW_LINE size = len ( arr ) NEW_LINE Solve ( arr , size , n ) NEW_LINE DEDENT