For the Rainbow Array Problem, I wrote the following Python code:
def main():
num=int(input())
for i in range(num):
n=int(input())
if rainbow(input()):
print("yes")
else:
print("no")
def rainbow(s):
d={}
count=0
l=s.split()
for i in range(len(l)):
l[i]=int(l[i])
i=0
for j in range(1, 8):
while l[i]==j:
count+=1
i+=1
if count==0:
return False
d[j]=count
count=0
for k in range(6, 0, -1):
while l[i]==k:
count+=1
i+=1
if i==len(l):
break
if count!=d[k]:
return False
count=0
if i!=len(l):
return False
return True
main()
I ran it on my system in the Python 3.5.0 Shell and it works exactly as intended (at least on the given sample). When I submitted it, I received a NZEC error. Can anybody guide me on why it was caused and how I may correct it?