human
Count subarrays which contains both the maximum and minimum array element | ''Function to count subarray containing both maximum and minimum array elements.
'' If the length of the  array is less than 2.
'' Find the index of  maximum element.
'' Find the index of  minimum element.
'' If i > j, then swap  the value of i and j.
'' Return the answer.
''Function to return max_element index.
''Function to return min_element index.
''Driver Code.
'' Function call"
How can the above be solved in Python?
assistant
#Here is code to count subarrays which contains both the maximum and minimum array element and the other steps required.
 def countSubArray ( arr , n ) :
	if ( n < 2 ) :
		return n ;
	i = max_element ( arr ) ;
	j = min_element ( arr ) ;
	if ( i > j ) :
		tmp = arr [ i ] ;
		arr [ i ] = arr [ j ] ;
		arr [ j ] = tmp ;
	return ( i + 1 ) * ( n - j ) ;
def max_element ( arr ) :
	idx = 0 ;
	max = arr [ 0 ] ;
	for i in range ( 1 , len ( arr ) ) :
		if ( max < arr [ i ] ) :
			max = arr [ i ] ;
			idx = i ;
	return idx ;
def min_element ( arr ) :
	idx = 0 ;
	min = arr [ 0 ] ;
	for i in range ( 1 , len ( arr ) ) :
		if ( arr [ i ] < min ) :
			min = arr [ i ] ;
			idx = i ;
	return idx ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 1 , 2 , 3 ] ;
	n = len ( arr ) ;
	print ( countSubArray ( arr , n ) ) ;