human
Minimum MEX from all subarrays of length K | Function to return minimum MEX from all K - length subarrays.
Stores element from [ 1 , N + 1 ] which are not present in subarray.
Store number 1 to N + 1 in set s.
Find the MEX of K - length subarray starting from index 0.
Find the MEX of all subarrays of length K by erasing arr [ i ] and inserting arr [ i - K ].
Store first element of set.
Updating the mex.
Print minimum MEX of all K length subarray.
Driver Code"
Solution in Python:
 ... Give me a code to minimum MEX from all subarrays of length K and the other steps required?
assistant
#Here is code to minimum MEX from all subarrays of length K and the other steps required.
 def minimumMEX ( arr , N , K ) :
	s = set ( )
	for i in range ( 1 , N + 2 , 1 ) :
		s . add ( i )
	for i in range ( K ) :
		s . remove ( arr [ i ] )
	mex = list ( s ) [ 0 ]
	for i in range ( K , N , 1 ) :
		s . remove ( arr [ i ] )
		s . add ( arr [ i - K ] )
		firstElem = list ( s ) [ 0 ]
		mex = min ( mex , firstElem )
	print ( mex )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
	K = 3
	N = len ( arr )
	minimumMEX ( arr , N , K )