Count subsequences which contains both the maximum and minimum array element | Function to calculate the count of subsequences ; Find the maximum from the array ; Find the minimum from the array ; If array contains only one distinct element ; Find the count of maximum ; Find the count of minimum ; Finding the result with given condition ; Driver Code ; Function call
def countSubSequence ( arr , n ) : NEW_LINE INDENT maximum = max ( arr ) NEW_LINE minimum = min ( arr ) NEW_LINE if maximum == minimum : NEW_LINE INDENT return pow ( 2 , n ) - 1 NEW_LINE DEDENT i = arr . count ( maximum ) NEW_LINE j = arr . count ( minimum ) NEW_LINE res = ( pow ( 2 , i ) - 1 ) * ( pow ( 2 , j ) - 1 ) * pow ( 2 , n - i - j ) NEW_LINE return res NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countSubSequence ( arr , n ) ) NEW_LINE