Function to count subarrays for each element where it is the minimum
function minSubarray ( arr , N ) { let result = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) result [ i ] = 0 ; let l = [ ] ; let r = [ ] ;