human
What is a code to count subarrays for every array element in which they are the minimum and the other steps required given the following:
Count subarrays for every array element in which they are the minimum | Set 2 | Function to count subarrays for each element where it is the minimum.
For the length of strictly larger numbers on the left of A [ i ].
Storing x in result [ i ].
For the length of strictly larger numbers on the right of A [ i ].
Store x * y in result array.
Print the result.
Driver Code.
Function Call"
Solution in Python:
assistant
#Here is code to count subarrays for every array element in which they are the minimum and the other steps required.
 def minSubarray ( arr , N ) :
	result = [ 0 ] * N
	l = [ ]
	r = [ ]
	for i in range ( N ) :
		count = 1 ;
		while ( len ( l ) != 0 and l [ - 1 ] [ 0 ] > arr [ i ] ) :
			count += l [ - 1 ] [ 1 ]
			l . pop ( )
		l . append ( [ arr [ i ] , count ] )
		result [ i ] = count ;
	for i in range ( N - 1 , - 1 , - 1 ) :
		count = 1 ;
		while ( len ( r ) != 0 and r [ - 1 ] [ 0 ] >= arr [ i ] ) :
			count += r [ - 1 ] [ 1 ]
			r . pop ( ) ;
		r . append ( [ arr [ i ] , count ] ) ;
		result [ i ] *= count
	for i in range ( N ) :
		print ( result [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 3 , 2 , 1 , 4 ]
	N = len ( arr )
	minSubarray ( arr , N )