RAINBOWA - Editorial

Every rainbow array must be:

  1. A palindrome
  2. Its first half should be non-decreasing (hence, 2nd half will be non-increasing, as its a palindrome)
  3. It contains every element 1,2,3,4,5,6,7 and nothing more, as a(i) is a “non-zero” positive integer.

While taking inputs, you can see if you have anything which does not belong to {1, 2, …, 7}. Also, maintain an array p[7] with every value zero, and as you encounter elements, update the corresponding array element to 1. By doing a linear search for zeroes in this array p, you can see if you have all elements from 1 to 7.

Then run a for loop through the first half of the array to see if its a palindrome and non-decreasing. TADA!

6 Likes

Can anyone please point out the mistake in my code, I am not able to find one. Thank you. Code has been provided in the link below

link text

19

1 2 3 4 4 5 6 7 7 6 7 7 6 5 4 4 3 2 1

should be “no”

but my AC code says its “yes”

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

I suggest that every upcoming number till the mid of the array should either be equal or greater than the previous number.

2 Likes

can anyone tell why i am getting NZEC?
please check my code here
https://www.codechef.com/viewsolution/16810625

i guess the error is in converting string to integer array.how to handle the NZEC?

THANKS IN ADVANCE

Hello can anyone point out the error in the given code. I have understood the question , but cant find out the error…it seems alright to me.
https://www.codechef.com/viewsolution/21937334
Thanks

Can I directly say by N that if N is even the answer is “no” and for Odd N I will check the condition ?

Can someone point out where am I going wrong CodeChef: Practical coding for everyone

Can someone point out where am I going wrong CodeChef: Practical coding for everyone

Incomplete question

1 Like

Not a rainbow array. “767” not allowed.

1 Like

it would be “no”

Exactly !!
Here is Link to my AC solution Which gives Yes for above testcase.

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

Were test cases for RAINBOWA Weak?

1 Like

Access denied! You don’t have permissions for this page.

the above test case 1 1 1 2 2 3 3 3 3 2 2 1 1 is not a rainbow array because rainbow array should go until it hits 7 and it should have all 1 2 3 4 5 6 7 without a skip over value.(1 2 4 5 6 7 6 5 4 2 1)(this is not a rainbow array)
(1 2 3 4 5 6 7 6 7 6 5 4 3 2 1 ) (this is also not a rainbow array either).

thanks bro for giving me some good explaination of test cases
can you plz tell me about this case 1 2 3 4 5 6 7 7 6 5 4 3 2 1 and its length is 14 is it “Yes” or “No”

Yes it is a rainbow. check here CodeChef: Practical coding for everyone

hi… my solution works CodeChef: Practical coding for everyone BUT I have a question:

I had to comment following code:

# if iNoOfElements % 2 == 0:
# print(“no”)
# continue

Note: iNoOfElements is equal to N (provided as Input)

above code is in the beginning. Idea is if the array is a palindrome, it has to be an odd number

if I remove above code, the answer is accepted. I am not able to understand. Can someone please help.

Here is my solution. Not sure what is wrong

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

Please can someone explain this how?