human
What is a code to difference between maximum and minimum average of all K and the other steps required given the following:
Difference between maximum and minimum average of all K | Function to find the difference between the maximum and minimum subarrays of length K.
Stores the sum of subarray over the range [ 0 , K ].
Iterate over the range [ 0 , K ].
Store min and max sum.
Iterate over the range [ K , N - K ].
Increment sum by arr [ i ] - arr [ i - K ].
Update max and min moving sum.
Return difference between max and min average.
Driver Code.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to difference between maximum and minimum average of all K and the other steps required.
 def Avgdifference ( arr , N , K ) :
	sum = 0
	for i in range ( K ) :
		sum += arr [ i ]
	min = sum
	max = sum
	for i in range ( K , N - K + 2 , 1 ) :
		sum += arr [ i ] - arr [ i - K ]
		if ( min > sum ) :
			min = sum
		if ( max < sum ) :
			max = sum
	return ( max - min ) / K
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 8 , 9 , 15 ]
	N = len ( arr )
	K = 2
	print ( Avgdifference ( arr , N , K ) )