Answer to Question #284544 in Python for Janardhan

Question #284544

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


1
Expert's answer
2022-01-03T09:05:46-0500
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS