human
Can you provide a code to largest Sum Contiguous Subarray having unique elements and the other steps required given the following:
Largest Sum Contiguous Subarray having unique elements | Function to calculate required maximum subarray sum.
Initialize two pointers.
Stores the unique elements.
Insert the first element.
Current max sum.
Global maximum sum.
Update sum & increment j.
Add the current element.
Update sum and increment i and remove arr [ i ] from set.
Remove the element from start position.
Return the maximum sum.
Driver Code.
Given array arr [ ].
Function call.
Print the maximum sum"
Solution in Python:
assistant
#Here is code to largest Sum Contiguous Subarray having unique elements and the other steps required.
 def maxSumSubarray ( arr ) :
	i = 0
	j = 1
	set = { }
	set [ arr [ 0 ] ] = 1
	sum = arr [ 0 ]
	maxsum = sum
	while ( i < len ( arr ) - 1 and j < len ( arr ) ) :
		if arr [ j ] not in set :
			sum = sum + arr [ j ]
			maxsum = max ( sum , maxsum )
			set [ arr [ j ] ] = 1
			j += 1
		else :
			sum -= arr [ i ]
			del set [ arr [ i ] ]
			i += 1
	return maxsum
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 , 1 , 5 ]
	ans = maxSumSubarray ( arr )
	print ( ans )