Problem: ARRT - getting RE(NZEC) error when submitting

I was getting Runtime error(NZEC) when I was submitting my solution for problem ARRT although it was running fine for sample test cases and other custom test cases…

My code:

def minSeq(A, B, n):
    poss=[]
    
    for k in range(n):
        if 2*n -2 +A[0]+k in B:
            p=2*n -2 +A[0]+k
            poss.append(p)
        if n-2+A[0]+k in B:
            p=n-2+k+A[0]
            poss.append(p)
        
        if len(poss)>0:
            break
        
        if A[0]-n-1-k in B:
            p=A[0]-n-1-k
        if A[0]-1-k in B:
            p=A[0]-n-1-k
        
        if len(poss)>0:
            break
    
    i = B.index(poss[0])
    
    
    
    
    fL=[]
    for j in range(n):
        fL.append((A[j]+B[(j+i)%n])%n)
        
    fL2=[]
    if(len(poss)==2):
        i2 = B.index(poss[1])
        fL2.append((A[j]+B[(j+i)%n])%n)
    
    
    return min(fL, fL2) if fL2 else fL
    
            
             
       
t=int(input())
ans=[]
    


for _ in range(t):
    n=int(input())
    if n==0:
        break;
    A=[int(x) for x in input().split()]
    B=[int(x) for x in input().split()]
    
    
    ans.append(minSeq(A, B ,n))
        
    
            
for a in ans:
    for _a in a:
        print(_a,end=' ')
    print()

He’s a random test input that causes it to crash:

1
9
16 17 14 9 7 13 6 3 2
12 6 14 11 10 15 7 8 17
1 Like

Thank you so much! you saved me! I will further work on my code to make it fully working…

1 Like