WA in RAINBOWA

Can one tell me why is this a wrong answer ? or where I might find test cases that would fail for the below code?

# cook your dish here
for tc in range(int(input())):
    num_elements = int(input())
    values = list(range(1,8))
    rainbow = list(map(int,input().split(' ')))
    for value in rainbow:
        if value in values:
            all_colors = True
        else:
            all_colors = False
            print('no')
            break
    
    if all_colors:
    
        for i in range(0,len(rainbow)//2+1):
            if rainbow[i] == rainbow[-i-1]:
                rbow = True
            else:
                rbow = False
                break

        if rbow == True:
            print('yes')
        else:
            print('no')

It fails the same testcase as this guy.

1 Like

Hey ssjgz,

This is my AC code btw, they both give YES:

# cook your dish here
for tc in range(int(input())):
    num_elements = int(input())
    rainbow = list(map(int,input().split(' ')))
    rainbow_rev = rainbow.copy()
    rainbow_rev.reverse()
    rainbow_set = set(list(range(1,8)))
    set_of_colors = set(rainbow)
    
    if rainbow==rainbow_rev and set_of_colors==rainbow_set:
        print('yes')
    else:
        print('no')

Ugh - the correct answer should be no, so weak testcases on this one, then :confused:

1 Like

Actually I tweaked the code, works for test cases as far as I can go. But still I do not get an AC:
Worst part is all solutions look the same. I will just check 20-30 solutions to this lame problem when I find time. Maybe I will know what I am missing.

# cook your dish here
for tc in range(int(input())):
    num_elements = int(input())
    values = list(range(1,8))
    rainbow = list(map(int,input().split(' ')))
    for value in rainbow:
        if value in values:
            all_colors = True
        else:
            all_colors = False
            print('no')
            break

    if all_colors:
    
        for i in range(0,len(rainbow)//2+1):
            if rainbow[i] == rainbow[-i-1]==7 and i - len(rainbow)//2 != 0:
                rbow = False
                break
            elif rainbow[i] == rainbow[-i-1]:
                rbow = True
            else:
                rbow = False
                break

        if rbow == True:
            print('yes')
        else:
            print('no')

PS : You have saved me a couple of time, I should have sent you a bouquet.

1 Like

Here’s mine (cpp) - https://www.codechef.com/viewsolution/27602871

It just methodically checks both the conditions:

  1. Must be a palindrome;
  2. After removing adjacent duplicates (i.e. collapsing runs of the same number into a single instance of that number), the remainder is exactly the list 1,2,3,4,5,6,7,6,5,4,3,2,1.

No bouquet required :slight_smile:

2 Likes

I mean yeah! I can try to do it a different way and it should work. But what irks me is the ambiguity of the solution. I get very itchy if I see something like that.

I will check out your solution as well.

1 Like