A has List of integers. In that list he wants to find the pivot index. The pivot index can be defined as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.
Further he wants that if there is no such index exists, he should get -1as the output and if there are multiple pivot indexes, he should get the left-most pivot index.


Input
2
1 7 3 6 5 6
1 2 3

Output
3
-1


Solution

n = int(input())
p=0
while p<n:
inputs=input().split(' ')
ar=[]
su=0
for x in inputs:
su = su + int(x)
ar.append(su)
i=0
le=len(ar)
while i < le -1:
if ar[i] == su - ar[i + 1]:
print(i + 1)
break;
i=i+1
else:
print(0)

p+=1 


if you have any problem in this code, take a screenshot and contact with Rishabh Chaubey.
Previous Post Next Post