leftMax [ i ] will contain max element on left of arr [ i ] excluding arr [ i ] . leftMin [ i ] will contain min element on left of arr [ i ] excluding arr [ i ] .
for i in range ( 1 , n ) : NEW_LINE INDENT leftMax [ i ] = max_sum NEW_LINE if ( arr [ i ] > max_sum ) : NEW_LINE INDENT max_sum = arr [ i ] NEW_LINE DEDENT leftMin [ i ] = min_sum NEW_LINE if ( arr [ i ] < min_sum ) : NEW_LINE INDENT min_sum = arr [ i ] NEW_LINE DEDENT DEDENT