Find the deleted value from the array when average of original elements is given | Function to return the missing element ; Find the sum of the array elements ; The numerator and the denominator of the equation ; If not divisible then X is not an integer it is a floating ponumber ; Return X ; Driver code
def findMissing ( arr , n , k , avg ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += arr [ i ] ; NEW_LINE DEDENT num = ( avg * ( n + k ) ) - sum ; NEW_LINE den = k ; NEW_LINE if ( num % den != 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT return ( int ) ( num / den ) ; NEW_LINE DEDENT k = 3 ; avg = 4 ; NEW_LINE arr = [ 2 , 7 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( findMissing ( arr , n , k , avg ) ) ; NEW_LINE