human
Rearrange array to make product of prefix sum array non zero | Function to rearrange array that satisfies the given condition.
Stores sum of elements of the given array.
Calculate totalSum.
If the totalSum is equal to 0.
No possible way to rearrange array.
If totalSum exceeds 0.
Rearrange the array in descending order.
Otherwise.
Rearrange the array in ascending order.
Driver Code"
Solution in Python:
 Write me a code to rearrange array to make product of prefix sum array non zero and the other steps required?
assistant
#Here is code to rearrange array to make product of prefix sum array non zero and the other steps required.
 def rearrangeArr ( arr , N ) :
	totalSum = 0
	for i in range ( N ) :
		totalSum += arr [ i ]
	if ( totalSum == 0 ) :
		print ( - 1 )
	elif ( totalSum > 0 ) :
		arr . sort ( reverse = True )
		print ( * arr , sep = ' ▁ ' )
	else :
		arr . sort ( )
		print ( * arr , sep = ' ▁ ' )
arr = [ 1 , - 1 , - 2 , 3 ]
N = len ( arr )
rearrangeArr ( arr , N ) ;