human
Find subarray of Length K with Maximum Peak | Function to find the subarray.
Make prefix array to store the prefix sum of peak count.
Count peak for previous index.
Check if this element is a peak.
Increment the count.
Check if number of peak in the sub array whose l = i is greater or not.
Print the result.
Driver code"
How can the above be solved in Python?
 Give me a code to find subarray of Length K with Maximum Peak and the other steps required?
assistant
#Here is code to find subarray of Length K with Maximum Peak and the other steps required.
 def findSubArray ( a , n , k ) :
	pref = [ 0 for i in range ( n ) ]
	pref [ 0 ] = 0
	for i in range ( 1 , n - 1 , 1 ) :
		pref [ i ] = pref [ i - 1 ]
		if ( a [ i ] > a [ i - 1 ] and a [ i ] > a [ i + 1 ] ) :
			pref [ i ] += 1
	peak = 0
	left = 0
	for i in range ( 0 , n - k + 1 , 1 ) :
		if ( pref [ i + k - 2 ] - pref [ i ] > peak ) :
			peak = pref [ i + k - 2 ] - pref [ i ]
			left = i
	print ( " Left ▁ = " , left + 1 )
	print ( " Right ▁ = " , left + k )
	print ( " Peak ▁ = " , peak )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 2 , 3 , 2 , 1 ]
	n = len ( arr )
	k = 3
	findSubArray ( arr , n , k )