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 ; Find the sum of the subarray arr [ i + 1. . . n - 1 ] ; Subtract the subarray sum ; 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 for i in range ( n - 1 ) : NEW_LINE INDENT subSum = 0 NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT subSum += arr [ j ] NEW_LINE DEDENT arr [ i ] -= subSum 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