human
Maximum possible sum of a window in an array such that elements of same window in other array are unique | Function to return maximum sum of window in B [ ] according to given constraints ..
Map is used to store elements and their counts ..
Initialize result.
calculating the maximum possible sum for each subarray containing unique elements ..
Remove all duplicate instances of A [ i ] in current window ..
Add current instance of A [ i ] to map and to current sum ..
Update result if current sum is more ..
Driver code"
Solution in Python:
 Give me a code to maximum possible sum of a window in an array such that elements of same window in other array are unique and the other steps required?
assistant
#Here is code to maximum possible sum of a window in an array such that elements of same window in other array are unique and the other steps required.
 def returnMaxSum ( A , B , n ) :
	mp = set ( )
	result = 0
	curr_sum = curr_begin = 0
	for i in range ( 0 , n ) :
		while A [ i ] in mp :
			mp . remove ( A [ curr_begin ] )
			curr_sum -= B [ curr_begin ]
			curr_begin += 1
		mp . add ( A [ i ] )
		curr_sum += B [ i ]
		result = max ( result , curr_sum )
	return result
if __name__ == " _ _ main _ _ " :
	A = [ 0 , 1 , 2 , 3 , 0 , 1 , 4 ]
	B = [ 9 , 8 , 1 , 2 , 3 , 4 , 5 ]
	n = len ( A )
	print ( returnMaxSum ( A , B , n ) )