Check if the array has an element which is equal to sum of all the remaining elements | function to check if such element exists or not ; storing frequency in dict ; stores the sum ; traverse the array and count the array element ; Only possible if sum is even ; if half sum is available ; Driver code
def isExists ( a , n ) : NEW_LINE INDENT freq = { i : 0 for i in a } NEW_LINE Sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ a [ i ] ] += 1 NEW_LINE Sum += a [ i ] NEW_LINE DEDENT if Sum % 2 == 0 : NEW_LINE INDENT if freq [ Sum // 2 ] : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT a = [ 5 , 1 , 2 , 2 ] NEW_LINE n = len ( a ) NEW_LINE if isExists ( a , n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT