human
Maximum sum of K | Function to count the number of distinct elements present in the array.
Insert all elements into the Set.
Return the size of set.
Function that finds the maximum sum of K - length subarray having same unique elements as arr [ ].
Not possible to find a subarray of size K.
Initialize Set.
Calculate sum of the distinct elements.
If the set size is same as the count of distinct elements.
Update the maximum value.
Driver code.
Stores the count of distinct elements"
Solution in Python:
assistant
#Here is code to maximum sum of K and the other steps required.
 def distinct ( arr , n ) :
	mpp = { }
	for i in range ( n ) :
		mpp [ arr [ i ] ] = 1
	return len ( mpp )
def maxSubSum ( arr , n , k , totalDistinct ) :
	if ( k > n ) :
		return 0
	maxm = 0
	sum = 0
	for i in range ( n - k + 1 ) :
		sum = 0
		st = set ( )
		for j in range ( i , i + k , 1 ) :
			sum += arr [ j ]
			st . add ( arr [ j ] )
		if ( len ( st ) == totalDistinct ) :
			maxm = max ( sum , maxm )
	return maxm
if __name__ == ' _ _ main _ _ ' :
	arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ]
	K = 6
	N = len ( arr )
	totalDistinct = distinct ( arr , N )
	print ( maxSubSum ( arr , N , K , totalDistinct ) )