human
Count ways of choosing a pair with maximum difference | Python Code to find no . of Ways of choosing a pair with maximum difference.
To find minimum and maximum of the array.
to find the count of minimum and maximum elements.
Count variables.
condition for all elements equal.
Driver code"
How can the above be solved in Python?
 ... Can you provide a code to count ways of choosing a pair with maximum difference and the other steps required?
assistant
#Here is code to count ways of choosing a pair with maximum difference and the other steps required.
 def countPairs ( a , n ) :
	mn = + 2147483647
	mx = - 2147483648
	for i in range ( n ) :
		mn = min ( mn , a [ i ] )
		mx = max ( mx , a [ i ] )
	c1 = 0
	c2 = 0
	for i in range ( n ) :
		if ( a [ i ] == mn ) :
			c1 += 1
		if ( a [ i ] == mx ) :
			c2 += 1
	if ( mn == mx ) :
		return n * ( n - 1 ) // 2
	else :
		return c1 * c2
a = [ 3 , 2 , 1 , 1 , 3 ]
n = len ( a )
print ( countPairs ( a , n ) )