human
Minimize the difference between minimum and maximum elements | Function to minimize the difference between minimum and maximum elements.
Find max and min elements of the array.
Check whether the difference between the max and min element is less than or equal to k or not.
Calculate average of max and min.
If the array element is greater than the average then decrease it by k.
If the array element is smaller than the average then increase it by k.
Find max and min of the modified array.
return the new difference.
Driver code"
How can the above be solved in Python?

=====
Can you provide a code to minimize the difference between minimum and maximum elements and the other steps required?
assistant
#Here is code to minimize the difference between minimum and maximum elements and the other steps required.
 def minimizeDiff ( arr , n , k ) :
	max_element = max ( arr )
	min_element = min ( arr )
	if ( ( max_element - min_element ) <= k ) :
		return ( max_element - min_element )
	avg = ( max_element + min_element ) // 2
	for i in range ( n ) :
		if ( arr [ i ] > avg ) :
			arr [ i ] -= k
		else :
			arr [ i ] += k
	max_element = max ( arr )
	min_element = min ( arr )
	return ( max_element - min_element ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 3 , 16 , 12 , 9 , 20 ]
	n = 5
	k = 3
	print ( " Max ▁ height ▁ difference ▁ = " , minimizeDiff ( arr , n , k ) )