human
Write me a code to subarray with largest sum after excluding its maximum element and the other steps required given the following:
Subarray with largest sum after excluding its maximum element | Function to find the maximum sum subarray by excluding the maximum element from the array.
Loop to store all the positive elements in the map.
Loop to iterating over the map and considering as the maximum element of the current including subarray.
Make the current element maximum.
Iterate through array and apply kadane 's algorithm.
Condition if current element is greater than mx then make the element - infinity.
Store the indices in some variable.
Driver Code.
Function Call"
Solution in Python:
assistant
#Here is code to subarray with largest sum after excluding its maximum element and the other steps required.
 def maximumSumSubarray ( arr , n ) :
	mp = { }
	for i in range ( n ) :
		if ( arr [ i ] >= 0 and arr [ i ] not in mp ) :
			mp [ arr [ i ] ] = 1
	first = 0
	last = 0
	ans = 0
	INF = 1e6
	for i in mp :
		mx = i
		curr = 0
		for j in range ( n ) :
			if ( curr == 0 ) :
				curr_start = j
			if arr [ j ] > mx :
				val = - INF
			else :
				val = arr [ j ] ;
			curr += val
			if ( curr < 0 ) :
				curr = 0
			if ( curr > ans ) :
				ans = curr
				first = curr_start
				last = j
	print ( first + 1 , last + 1 )
if __name__ == " _ _ main _ _ " :
	arr = [ 5 , - 2 , 10 , - 1 , 4 ]
	size = len ( arr )
	maximumSumSubarray ( arr , size )