Sum of the updated array after performing the given operation | Utility function to return the sum of the array ; Function to return the sum of the modified array ; Subtract the subarray sum ; Sum of subarray arr [ i ... n - 1 ] ; Return the sum of the modified array ; Driver code
def sumArr ( arr , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += arr [ i ] ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT def sumModArr ( arr , n ) : NEW_LINE INDENT subSum = arr [ n - 1 ] ; NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT curr = arr [ i ] ; NEW_LINE arr [ i ] -= subSum ; NEW_LINE subSum += curr ; NEW_LINE DEDENT return sumArr ( arr , n ) ; NEW_LINE DEDENT arr = [ 40 , 25 , 12 , 10 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( sumModArr ( arr , n ) ) ; NEW_LINE