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
def minSubarray ( arr , N ) : NEW_LINE INDENT m = { } NEW_LINE for i in range ( N ) : NEW_LINE INDENT mini = 10 ** 9 NEW_LINE for j in range ( i , N ) : NEW_LINE INDENT mini = min ( mini , arr [ j ] ) NEW_LINE m [ mini ] = m . get ( mini , 0 ) + 1 NEW_LINE DEDENT DEDENT for i in arr : NEW_LINE INDENT print ( m [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 2 , 1 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE minSubarray ( arr , N ) NEW_LINE DEDENT