Input Description:
You are given an integer ‘n’ denoting the number of elements in array. Next line contains n space separated integers
Output Description:
Print the max length of that array with sum 0 and print -1 if not possible
Sample Input : 6 -4 3 1 0 0 6
Sample Output : 5
#My code
n=int(input())
n1=input().split()
sum=0
pos=0
for i in range(0,len(n1)):
sum=sum+int(n1[i])
if sum==0:
pos=i+1
continue
if pos>0:
print(pos)
else:
print(-1)
Is this test case wrong? or my code is wrong??
Input:
5
1 3 1 0 0 6
Expected Output:
2
Actual Output:
-1