human
Count of subarrays of size K with average at least M | Function to count the subarrays of size K having average at least M.
Stores the resultant count of subarray.
Stores the sum of subarrays of size K.
Add the values of first K elements to the sum.
Increment the count if the current subarray is valid.
Traverse the given array.
Find the updated sum.
Check if current subarray is valid or not.
Return the count of subarrays.
Driver Code"
How can the above be solved in Python?
 ... Give me a code to count of subarrays of size K with average at least M and the other steps required?
assistant
#Here is code to count of subarrays of size K with average at least M and the other steps required.
 def countSubArrays ( arr , N , K , M ) :
	count = 0
	sum = 0
	for i in range ( K ) :
		sum += arr [ i ]
	if sum >= K * M :
		count += 1
	for i in range ( K , N ) :
		sum += ( arr [ i ] - arr [ i - K ] )
		if sum >= K * M :
			count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 6 , 3 , 2 , 1 , 3 , 9 ]
	K = 2
	M = 4
	N = len ( arr )
	count = countSubArrays ( arr , N , K , M )
	print ( count )