Length of array pair formed where one contains all distinct elements and other all same elements | Function to find the max size possible ; Counting the maximum frequency ; Counting total distinct elements ; Find max of both the answer ; Driver code
def findMaxSize ( a , n ) : NEW_LINE INDENT frq = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT frq [ a [ i ] ] += 1 NEW_LINE DEDENT maxfrq = max ( frq ) NEW_LINE dist = n + 1 - frq . count ( 0 ) NEW_LINE ans1 = min ( maxfrq - 1 , dist ) NEW_LINE ans2 = min ( maxfrq , dist - 1 ) NEW_LINE ans = max ( ans1 , ans2 ) NEW_LINE return ans NEW_LINE DEDENT arr = [ 4 , 2 , 4 , 1 , 4 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMaxSize ( arr , n ) ) NEW_LINE