RAINBOWA - Editorial

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

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 https://www.codechef.com/viewsolution/24013588

hi… my solution works https://www.codechef.com/viewsolution/24069803 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?

This also not rainbow array 1 2 3 4 5 6 7 7 6 5 4 3 2 1

please Tell Me What is problem with my code

i already take care of every base case

#include
using namespace std;
#include<bits/stdc++.h>
int main() {

``````int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n+1];
for(int i=1;i<=n;i++)
cin>>arr[i];
int start=1;
int end=n;
int flag=1;
while(start<=end)
{
int val1= arr[start]-arr[start+1];
int val2=arr[end]-arr[end-1];
if(val1!=val2 || (val1<-1 && val2<-1) || (arr[start]>7 || arr[end]>7))
{
flag=0; // not beautiful
break;
}
start++;
end--;
}
if(flag==0)
cout<<"no"<<"\n";
else
cout<<"yes"<<"\n";

}
return 0;
``````

}

Guys please help i do all my effort and thinking but i checked 40 testcase my code giving right answer but if get fails in codechef please help me friends

#include
using namespace std;
#include<bits/stdc++.h>
int main() {

``````int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int start=0;
int end=n-1;
int flag=1; //assume the already rainbow
while(start<=end)
{
if(arr[start]!=arr[end] || arr[start]>7 || arr[end]>7)
{
flag=0;
break;
}

start++;
end--;
}
if(flag==0)
cout<<"no"<<"\n";
else
cout<<"yes"<<"\n";

}
return 0;
``````

}

Over a month late, but looking at your most recent submission - consider the testcase:

``````1
13
1 3 3 4 5 6 7 6 5 4 3 3 1
``````

Edit:

May as well post my solution - it’s unusually terse, for me, as I got the C++ Standard Library to do all the heavy-lifting

2 Likes

If you are looking for better editorial for the problem, you can visit to the following link:
Rainbow Array Editorial

2 Likes

Might be something to do with this:

https://discuss.codechef.com/t/codechef-solution-submit-issue/45664/4

?

Not able to Submit my code for this problem. Please help.

#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int n,flag=0;
cin>>n;
int a[n];
int y[7]={0};
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==1||a[i]==2||a[i]==3||a[i]==4||a[i]==5||a[i]==6||a[i]==7)
y[a[i]-1]=1;
}
for(int i=0;i<7;i++){
if(y[i]==0){
flag=1;
// cout<<“error pos1”;
break;
}
}
for(int i=0;i<n/2 && !flag;i++){
if(a[i]!=a[n-i-1]){
flag=1;
// cout<<“error pos2”;
break;
}
}
if(flag==1)
cout<<“no”<<endl;
else
cout<<“yes”;
}
}
so that was my code ,can someone please point out why I am unable to get AC ?

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

Edit:

Managed to decipher it - consider the testcase:

``````1
13
1 2 3 4 5 7 6 7 5 4 3 2 1
``````

Edit:

Also, you’re not printing a new line if the answer is `yes`.

2 Likes

please tell me if 1 2 3 4 5 6 7 7 6 5 4 3 2 1 is rainbow array or not with apt reason.