RAINBOWA - Editorial

After spending some time and going through every edge cases,

Here, the problem is-

1. Array must-have element 1 to 7 numbers, other than this numbers, ans. = “no”.

For Example-
2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 , ans=“no”.

2. If the array size is even that does not means the ans. = “no”

For Example-
1 2 3 4 5 6 7 7 6 5 4 3 2 1 – it is rainbow , ans = “yes”.

3. After dividing the array to compare, in a first-half the difference between two elements must be 0 or 1(in an increasing way)

For Example -
1 2 4 5 6 7 6 5 4 2 1 , ans=“no”

I Hope, This will help you all!

Can anyone tell me what is wrong in my code.
‘’’
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{

public static void main (String[] args) throws java.lang.Exception
{

	Scanner s=new Scanner(System.in);

	int t=s.nextInt();
    while(t-->0)
    {
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++)
        a[i]=s.nextInt();
        int i=0,j=n-1;
        int k=1;
        int c=0;
        while(i<=j)
        {
            if(a[i]==a[j] && a[i]==k)
            {
                i++;
                j--;
                continue;
            }
            else if(a[i]==a[j] && a[i]==k+1)
            {
                k++;
                i++;
                j--;
            }
            else if(a[i]==a[j] && a[i]!=k+1)
            {
               // System.out.println(i+" "+j);
                c=1;
                break;
            }
            else
            {
              // System.out.println("i="+i+" "+j);
                c=1;
                break;
            }
        }
        if(c==1)
        System.out.println("no");
        else
        System.out.println("yes");
       
    }
    
	s.close();
	
}

}

‘’’

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:

Deciphered it: RAINBOWA - Editorial - #52 by ssjgz

Here is my code. I don’t understand why it can’t pass first sub task while passes second.
https://www.codechef.com/viewsolution/44109339

Please someone point out the mistake

Consider the test input:

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

Thanks

Hi your solution was really very understandable, thanks for the solution

although I have one question, what is ‘’‘cassert’’’ and why have you used it here

1 Like

cassert is the header file that includes the declaration of the assert macro, which I’ve used in my read function to check that I’m reading the input correctly.

1 Like

Kya baat…

Can anyone help me out to find which case I am missing?
Here is my solution
Passes the second part but failed in first.

Consider the test input:

1
12
1 2 3 4 5 6 6 5 4 3 2 1
1 Like

Thanks @ssjgz . Now got accepted.

1 Like