human
A Sum Array Puzzle | Python3 implementation of above approach.
Allocate memory for temporary arrays leftSum [ ] , rightSum [ ] and Sum [ ].
Left most element of left array is always 0.
Rightmost most element of right array is always 0.
Construct the left array.
Construct the right array.
Construct the sum array using left [ ] and right [ ].
print the constructed prod array.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to a Sum Array Puzzle and the other steps required.
 def sumArray ( arr , n ) :
	leftSum = [ 0 for i in range ( n ) ]
	rightSum = [ 0 for i in range ( n ) ]
	Sum = [ 0 for i in range ( n ) ]
	i , j = 0 , 0
	leftSum [ 0 ] = 0
	rightSum [ n - 1 ] = 0
	for i in range ( 1 , n ) :
		leftSum [ i ] = arr [ i - 1 ] + leftSum [ i - 1 ]
	for j in range ( n - 2 , - 1 , - 1 ) :
		rightSum [ j ] = arr [ j + 1 ] + rightSum [ j + 1 ]
	for i in range ( 0 , n ) :
		Sum [ i ] = leftSum [ i ] + rightSum [ i ]
	for i in range ( n ) :
		print ( Sum [ i ] , end = " ▁ " )
arr = [ 3 , 6 , 4 , 8 , 9 ]
n = len ( arr )
sumArray ( arr , n )