Construct array with sum of product of same indexed elements in the given array equal to zero | Function to generate a new array with product of same indexed elements with arr [ ] equal to 0 ; Stores sum of same indexed array elements of arr and new array ; Traverse the array ; If i is an even number ; Insert arr [ i + 1 ] into the new array newArr [ ] ; Insert - arr [ i - 1 ] into the new array newArr [ ] ; Print new array elements ; Driver code
def constructNewArraySumZero ( arr , N ) : NEW_LINE INDENT newArr = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT newArr [ i ] = arr [ i + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT newArr [ i ] = - arr [ i - 1 ] NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT print ( newArr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , - 5 , - 6 , 8 ] NEW_LINE N = len ( arr ) NEW_LINE constructNewArraySumZero ( arr , N ) NEW_LINE