human
Write me a code to minimum difference between max and min of all K and the other steps required given the following:
Minimum difference between max and min of all K | Returns min difference between max and min of any K - size subset.
sort the array so that close elements come together ..
initialize result by a big integer number.
loop over first ( N - K ) elements of the array only.
get difference between max and min of current K - sized segment.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum difference between max and min of all K and the other steps required.
 def minDifferenceAmongMaxMin ( arr , N , K ) :
	arr . sort ( )
	res = 2147483647
	for i in range ( ( N - K ) + 1 ) :
		curSeqDiff = arr [ i + K - 1 ] - arr [ i ]
		res = min ( res , curSeqDiff )
	return res
arr = [ 10 , 20 , 30 , 100 , 101 , 102 ]
N = len ( arr )
K = 3
print ( minDifferenceAmongMaxMin ( arr , N , K ) )