human
What is a code to check if there exist two elements in an array whose sum is equal to the sum of rest of the array and the other steps required given the following:
Check if there exist two elements in an array whose sum is equal to the sum of rest of the array | Function to check whether two elements exist whose sum is equal to sum of rest of the elements ..
Find sum of whole array.
/ If sum of array is not even than we can not divide it into two part.
For each element arr [ i ] , see if there is another element with value sum - arr [ i ].
If element exist than return the pair.
Driver Code"
Solution in Python:
assistant
#Here is code to check if there exist two elements in an array whose sum is equal to the sum of rest of the array and the other steps required.
 def checkPair ( arr , n ) :
	s = set ( )
	sum = 0
	for i in range ( n ) :
		sum += arr [ i ]
	if sum % 2 != 0 :
		return False
	sum = sum / 2
	for i in range ( n ) :
		val = sum - arr [ i ]
		if arr [ i ] not in s :
			s . add ( arr [ i ] )
		if val in s :
			print ( " Pair ▁ elements ▁ are " , arr [ i ] , " and " , int ( val ) )
arr = [ 2 , 11 , 5 , 1 , 4 , 7 ]
n = len ( arr )
if checkPair ( arr , n ) == False :
	print ( " No ▁ pair ▁ found " )