RAINBOWA Problem

Hello everyone. I have provided the below solution to the problem here :frowning: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]))**

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

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