# RAINBOWA Problem

Hello everyone. I have provided the below solution to the problem here https://www.codechef.com/problems/RAINBOWA)

My solution works with all the test casesβ¦but if i submit it clears only the first one. Many other solutions clear both. I donβt find any error in my code. If u do, pease let me know.

def func_check(n_arg, str_arg):
** ββ" function that takes the n_arg as the size of the array and**
** str_arg as the string of elements of the array"""**

** #flag is a variable used to check if the numbers from 1 to 7 are present or not**
** flag = True **

** #temp_list stores the elements of the array**
** temp_list = str_arg.split(β ')**

** # we check if the numbers from not from the range 1 to 7 are present or not **
** for i in range(n_arg):**
** if (int(temp_list[i])>7 or int(temp_list[i])<1):**
** flag = False**
** break**
** if not flag:**
** return βnoβ**

** # we check if all numbers from 1 to 7 are present**
** s1 = β7β in temp_list**
** s2 = β6β in temp_list**
** s3 = β5β in temp_list**
** s4 = β4β in temp_list**
** s5 = β3β in temp_list**
** s6 = β2β in temp_list**
** s7 = β1β in temp_list**

** if not (s1 and s2 and s3 and s4 and s5 and s6 and s7):**
** return βnoβ**

** ββ" we check if the numbers 1 to 7 appear as in increasing order i.e**
** 1 followed by 2 followed by 3 and so on till 7"""**

** s1 = str_arg.find(β1β)**
** s2 = str_arg.find(β2β)**
** s3 = str_arg.find(β3β)**
** s4 = str_arg.find(β4β)**
** s5 = str_arg.find(β5β)**
** s6 = str_arg.find(β6β)**
** s7 = str_arg.find(β7β)**

** q1 = (s1<s2) and (s2<s3) and (s3<s4) and (s4<s5) and (s5<s6) and (s6<s7)**

** if not(q1):**
** return βnoβ**

** while temp_list[0]!=β7β:**
** if temp_list[0] == temp_list[-1]:**
** temp_list.remove(temp_list[0])**
** temp_list.pop()**
** else:**
** return βnoβ**

** if len(temp_list)==0:**
** return βyesβ**
** else:**
** flag = True**
** for i in temp_list:**
** if i != β7β:**
** flag = False**
** if flag:**
** return βyesβ**
** else:**
** return βnoβ**

""" obtain the number of testcases ββ" **
num_of_testcases = 0
try:
** num_of_testcases = int(input())

except EOFError:
** pass**

""" store the test cases here"""
testcases = list()

for i in range(num_of_testcases):
** try:**
** num_of_elements = int(input())**
** temp_string = input()**
** l = list()**
** l.append(num_of_elements)**
** l.append(temp_string)**
** testcases.append(l)**
** except EOFError:**
** pass**

if num_of_elements == 0:
** pass**
else:
** for i in testcases:**
** print(func_check(i[0], i[1]))**

Edit:

Iβm just going to assume that you meant this one:

https://www.codechef.com/viewsolution/32557221

in which case, consider the test input:

``````1
15
1 2 3 4 5 6 5 7 5 6 5 4 3 2 1
``````
1 Like