# RAINBOWA Problem

Hello everyone. I have provided the below solution to the problem here RAINBOWA Problem - CodeChef)

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