human
Min and max length subarray having adjacent element difference atmost K | Function to find the maximum and minimum length subarray.
Initialise minimum and maximum size of subarray in worst case.
Left will scan the size of possible subarray in left of selected element.
Right will scan the size of possible subarray in right of selected element.
Temp will store size of group associateed with every element.
Loop to find size of subarray for every element of array.
Left will move in left direction and compare difference between itself and element left to it.
Right will move in right direction and compare difference between itself and element right to it.
If subarray of much lesser or much greater is found than yet known then update.
Print minimum and maximum possible size of subarray.
Driver Code.
Function call to find maximum and minimum possible sub array"
How can the above be solved in Python?
 ... Write me a code to min and max length subarray having adjacent element difference atmost K and the other steps required?
assistant
#Here is code to min and max length subarray having adjacent element difference atmost K and the other steps required.
 def findMaxMinSubArray ( arr , K , n ) :
	min = n
	max = 0
	left = 0
	right = n
	tmp = 0
	for i in range ( 0 , n ) :
		tmp = 1
		left = i
		while ( left - 1 >= 0 and abs ( arr [ left ] - arr [ left - 1 ] ) <= K ) :
			left = left - 1
			tmp = tmp + 1
		right = i
		while ( right + 1 <= n - 1 and abs ( arr [ right ] - arr [ right + 1 ] ) <= K ) :
			right = right + 1
			tmp = tmp + 1
		if ( min > tmp ) :
			min = tmp
		if ( max < tmp ) :
			max = tmp
	print ( min , end = ' , ▁ ' )
	print ( max , end =   ' ' )
arr = [ 1 , 2 , 5 , 6 , 7 ]
K = 2
n = len ( arr )
findMaxMinSubArray ( arr , K , n )