Beginner#1 Rainbow Array NZEC error

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?

Your code fails for input as:-

1

7

1 2 3 4 5 6 7

Actually, this statement is causing NZEC error at the end:-

while l[i]==j:

So, how do I solve this?

Here is my solution it is python hope it helps !

what i essentially did was checked for palindrome and increment the checking factor by one starting with zero and also note the middle element has to be 7 and rest all cases are false

x = int(input())
count = 0
for i in range(x):
y = list(map(int, input().split(" ")))
size_y = len(y)
if size_y % 2 == 0:
print(‘No’)
else:
mid = (size_y // 2) + 1
mid_side = (size_y // 2)
if y[mid_side] - y[mid] == 1:
left = y[:mid - 1]
right = y[mid:]
new_right = []
for l in range(len(right), 0, -1):
new_right.append(right[l - 1])
for j in range(len(left)):
if left[j] == new_right[j]:
count = count + 1
if count == mid_side:
print(‘Yes’)
else:
print(‘No’)
else:
print(‘No’)