Subsequence pair from given Array having all unique and all same elements respectively | Function to find the maximum length of subsequences with given property ; To store the frequency ; Traverse the array to store the frequency ; M . size ( ) given count of distinct element in arr [ ] ; Traverse map to find max frequency ; Find the maximum length on the basis of two cases in the approach ; Driver Code ; Function call
def maximumSubsequence ( arr , N ) : NEW_LINE INDENT M = { i : 0 for i in range ( 100 ) } NEW_LINE for i in range ( N ) : NEW_LINE INDENT M [ arr [ i ] ] += 1 NEW_LINE DEDENT distinct_size = len ( M ) NEW_LINE maxFreq = 1 NEW_LINE for value in M . values ( ) : NEW_LINE INDENT maxFreq = max ( maxFreq , value ) NEW_LINE DEDENT print ( max ( min ( distinct_size , maxFreq - 1 ) , min ( distinct_size - 1 , maxFreq ) ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE maximumSubsequence ( arr , N ) NEW_LINE DEDENT