human
Count subarrays having total distinct elements same as original array | Function to calculate distinct sub - array.
Count distinct elements in whole array.
Reset the container by removing all elements.
Use sliding window concept to find count of subarrays having k distinct elements ..
If window size equals to array distinct element size , then update answer.
Decrease the frequency of previous element for next sliding window.
If frequency is zero then decrease the window size.
Driver code"
Solution in Python:
 ... Write me a code to count subarrays having total distinct elements same as original array and the other steps required?
assistant
#Here is code to count subarrays having total distinct elements same as original array and the other steps required.
 def countDistictSubarray ( arr , n ) :
	vis = dict ( )
	for i in range ( n ) :
		vis [ arr [ i ] ] = 1
	k = len ( vis )
	vid = dict ( )
	ans = 0
	right = 0
	window = 0
	for left in range ( n ) :
		while ( right < n and window < k ) :
			if arr [ right ] in vid . keys ( ) :
				vid [ arr [ right ] ] += 1
			else :
				vid [ arr [ right ] ] = 1
			if ( vid [ arr [ right ] ] == 1 ) :
				window += 1
			right += 1
		if ( window == k ) :
			ans += ( n - right + 1 )
		vid [ arr [ left ] ] -= 1
		if ( vid [ arr [ left ] ] == 0 ) :
			window -= 1
	return ans
arr = [ 2 , 1 , 3 , 2 , 3 ]
n = len ( arr )
print ( countDistictSubarray ( arr , n ) )