human
Check if an array of 1 s and 2 s can be divided into 2 parts with equal sum | Function to check if it is possible to split the array in two halfs with equal Sum.
Calculate Sum of elements and count of 1 's.
If total Sum is odd , return False.
If Sum of each half is even , return True.
If Sum of each half is even but there is atleast one 1.
Driver Code"
Solution in Python:
assistant
#Here is code to check if an array of 1 s and 2 s can be divided into 2 parts with equal sum and the other steps required.
 def isSpiltPossible ( n , a ) :
	Sum = 0
	c1 = 0
	for i in range ( n ) :
		Sum += a [ i ]
		if ( a [ i ] == 1 ) :
			c1 += 1
	if ( Sum % 2 ) :
		return False
	if ( ( Sum // 2 ) % 2 == 0 ) :
		return True
	if ( c1 > 0 ) :
		return True
	else :
		return False
n = 3
a = [ 1 , 1 , 2 ]
if ( isSpiltPossible ( n , a ) ) :
	print ( " YES " )
else :
	print ( " NO " )