human
Can you provide 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 calculate total number of sub - arrays for each element where that element is occurring as the minimum element.
Map for storing the number of sub - arrays for each element.
Traverse over all possible subarrays.
Minimum in each subarray.
Print result.
Driver Code.
Function Call"
How can the above be solved 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 ) :
	m = { }
	for i in range ( N ) :
		mini = 10 ** 9
		for j in range ( i , N ) :
			mini = min ( mini , arr [ j ] )
			m [ mini ] = m . get ( mini , 0 ) + 1
	for i in arr :
		print ( m [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 2 , 1 , 4 ]
	N = len ( arr )
	minSubarray ( arr , N )