You are not logged in. Please login at www.codechef.com to post your questions!

×

# Beginner#1 Rainbow Array NZEC error

 0 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? asked 09 Sep '17, 16:36 3●2 accept rate: 0%

 0 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: answered 09 Sep '17, 19:20 11●2 accept rate: 0% So, how do I solve this? (09 Sep '17, 20:18)
 0 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 answered 09 Sep '17, 23:30 94●4 accept rate: 0%
 0 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')  answered 03 Jun '18, 02:30 2★kai1999 -1●1 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×42

question asked: 09 Sep '17, 16:36

question was seen: 271 times

last updated: 03 Jun '18, 02:30