human
What is a code to count of subarrays with largest element at least twice the largest of remaining elements and the other steps required given the following:
Count of subarrays with largest element at least twice the largest of remaining elements | Function to find count of subarrays which have max element greater than twice maximum of all other elements.
Stores the maximum element of the array.
Traverse the given array.
If the value of 2 * arr [ i ] is greater than mx.
Update the value of L and break out of loop.
If the value 2 * arr [ i ] is greater than mx.
Update the value of R and break out of loop.
Print the final answer.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to count of subarrays with largest element at least twice the largest of remaining elements and the other steps required.
 def countSubarray ( arr , n ) :
	count = 0
	L = 0
	R = 0
	mx = max ( arr )
	for i in range ( n ) :
		if ( arr [ i ] * 2 > mx ) :
			L = i
			break
	i = n - 1
	while ( i >= 0 ) :
		if ( arr [ i ] * 2 > mx ) :
			R = i
			break
		i -= 1
	print ( ( L + 1 ) * ( n - R ) )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 6 , 10 , 9 , 7 , 3 ]
	N = len ( arr )
	countSubarray ( arr , N )