human
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"
Solution in Python:
assistant
#Here is code to count subsequences which contains both the maximum and minimum array element and the other steps required.
 def countSubSequence ( arr , n ) :
	maximum = max ( arr )
	minimum = min ( arr )
	if maximum == minimum :
		return pow ( 2 , n ) - 1
	i = arr . count ( maximum )
	j = arr . count ( minimum )
	res = ( pow ( 2 , i ) - 1 ) * ( pow ( 2 , j ) - 1 ) * pow ( 2 , n - i - j )
	return res
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
print ( countSubSequence ( arr , n ) )