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]))**