human
Count of subarrays with maximum value as K | Function to count the subarrays with maximum not greater than K.
If arr [ i ] > k then arr [ i ] cannot be a part of any subarray ..
Count the number of elements where arr [ i ] is not greater than k ..
Summation of all possible subarrays in the variable ans ..
Function to count the subarrays with maximum value is equal to K.
Stores count of subarrays with max <= k - 1..
Stores count of subarrays with max >= k + 1..
Stores count of subarrays with max = k ..
Driver Code.
Given Input.
Function Call"
Solution in Python:

=====
Write me a code to count of subarrays with maximum value as K and the other steps required?
assistant
#Here is code to count of subarrays with maximum value as K and the other steps required.
 def totalSubarrays ( arr , n , k ) :
	ans = 0
	i = 0
	while ( i < n ) :
		if ( arr [ i ] > k ) :
			i += 1
			continue
		count = 0
		while ( i < n and arr [ i ] <= k ) :
			i += 1
			count += 1
		ans += ( ( count * ( count + 1 ) ) // 2 )
	return ans
def countSubarrays ( arr , n , k ) :
	count1 = totalSubarrays ( arr , n , k - 1 )
	count2 = totalSubarrays ( arr , n , k )
	ans = count2 - count1
	return ans
if __name__ == ' _ _ main _ _ ' :
	n = 4
	k = 3
	arr = [ 2 , 1 , 3 , 4 ]
	print ( countSubarrays ( arr , n , k ) )