Draw a flow chart and construct a python program to accept a list of N numbers .the job is to determine if there Exists an element in the list such that sum of the elements on its left is equal to the sum of the elements on its right if such elements exists print index of elements.ifthere is no such elements then sum is zero
def solution(fooBar, n):
preSum = [0] * n
preSum[0] = fooBar[0]
for i in range(1, n):
preSum[i] = preSum[i - 1] + fooBar[i]
postSum = [0] * n
postSum[n - 1] = fooBar[n - 1]
for i in range(n - 2, -1, -1):
postSum[i] = postSum[i + 1] + fooBar[i]
for i in range(1, n - 1, 1):
if preSum[i] == postSum[i]:
return fooBar[i]
return -1
Comments
Leave a comment