human
Minimum length subarray containing all unique elements after Q operations | Function to find minimum size subarray of all array elements.
Updating the array after processing each query.
Making it to 0 - indexing.
Prefix sum array concept is used to obtain the count array.
Iterating over the array to get the final array.
Variable to get count of all unique elements.
Hash to maintain perviously occurred elements.
Loop to find the all unique elements.
Array to maintain counter of encountered elements.
Variable to store answer.
Using two pointers approach.
Increment counter if occurred once.
When all unique elements are found.
update answer with minimum size.
Decrement count of elements from left.
Decrement counter.
Driver code"
Solution in Python:
assistant
#Here is code to minimum length subarray containing all unique elements after Q operations and the other steps required.
 def subarrayLength ( A , R , N , M ) :
	for i in range ( M ) :
		l = R [ i ] [ 0 ]
		r = R [ i ] [ 1 ] + 1
		l -= 1
		r -= 1
		A [ l ] += 1
		if ( r < N ) :
			A [ r ] -= 1
	for i in range ( 1 , N ) :
		A [ i ] += A [ i - 1 ]
	count = 0
	s = [ ]
	for i in range ( N ) :
		if ( A [ i ] not in s ) :
			count += 1
		s . append ( A [ i ] )
	repeat = [ 0 ] * ( count + 1 )
	ans = N
	counter , left , right = 0 , 0 , 0
	while ( right < N ) :
		cur_element = A [ right ]
		repeat [ cur_element ] += 1
		if ( repeat [ cur_element ] == 1 ) :
			counter += 1
		while ( counter == count ) :
			ans = min ( ans , right - left + 1 )
			cur_element = A [ left ]
			repeat [ cur_element ] -= 1
			left += 1
			if ( repeat [ cur_element ] == 0 ) :
				counter -= 1
		right += 1
	return ans
if __name__ == " _ _ main _ _ " :
	N , queries = 8 , 6
	Q = [ [ 1 , 4 ] , [ 3 , 4 ] , [ 4 , 5 ] , [ 5 , 5 ] , [ 7 , 8 ] , [ 8 , 8 ] ]
	A = [ 0 ] * N
	print ( subarrayLength ( A , Q , N , queries ) )