Maximize array product by changing any array element arr [ i ] to ( | Function to find array with maximum product by changing array elements to ( - 1 ) arr [ i ] - 1 ; Traverse the array ; Applying the operation on all the positive elements ; Stores maximum element in array ; Stores index of maximum element ; Check if current element is greater than the maximum element ; Find index of the maximum element ; Perform the operation on the maximum element ; Prthe elements of the array ; Driver Code ; Function Call
def findArrayWithMaxProduct ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] >= 0 ) : NEW_LINE INDENT arr [ i ] = - arr [ i ] - 1 NEW_LINE DEDENT DEDENT if ( N % 2 == 1 ) : NEW_LINE INDENT max_element = - 1 NEW_LINE index = - 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( abs ( arr [ i ] ) > max_element ) : NEW_LINE INDENT max_element = abs ( arr [ i ] ) NEW_LINE index = i NEW_LINE DEDENT DEDENT arr [ index ] = - arr [ index ] - 1 NEW_LINE DEDENT for i in arr : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 3 , 0 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE findArrayWithMaxProduct ( arr , N ) NEW_LINE DEDENT