human
Maximum sum of K | Function to count the number of distinct elements present in the array.
Insert array elements into set.
Return the st size.
Function to calculate maximum sum of K - length subarray having same unique elements as arr [ ].
Not possible to find an subarray of length K from an N - sized array , if K > N.
Traverse the array.
Update the mp.
If i >= K , then decrement arr [ i - K ] element 's one  occurence.
If frequency of any element is 0 then remove the element.
If mp size is same as the count of distinct elements of array arr [ ] then update maximum sum.
Function that finds the maximum sum of K - length subarray having same number of distinct elements as the original array.
Size of array.
Stores count of distinct elements.
Print maximum subarray sum.
Driver Code.
Function Call"
Solution in Python:
assistant
#Here is code to maximum sum of K and the other steps required.
 def distinct ( arr , N ) :
	st = set ( )
	for i in range ( N ) :
		st . add ( arr [ i ] )
	return len ( st )
def maxSubarraySumUtil ( arr , N , K , totalDistinct ) :
	if ( K > N ) :
		return 0
	mx = 0
	sum = 0
	mp = { }
	for i in range ( N ) :
		if ( arr [ i ] in mp ) :
			mp [ arr [ i ] ] += 1
		else :
			mp [ arr [ i ] ] = 1
		sum += arr [ i ]
		if ( i >= K ) :
			if ( arr [ i - K ] in mp ) :
				mp [ arr [ i - K ] ] -= 1
				sum -= arr [ i - K ]
			if ( arr [ i - K ] in mp and mp [ arr [ i - K ] ] == 0 ) :
				mp . remove ( arr [ i - K ] )
		if ( len ( mp ) == totalDistinct ) :
			mx = max ( mx , sum )
	return mx
def maxSubarraySum ( arr , K ) :
	N = len ( arr )
	totalDistinct = distinct ( arr , N )
	print ( maxSubarraySumUtil ( arr , N , K , totalDistinct ) )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ]
	K = 6
	maxSubarraySum ( arr , K )