trouble with "chef and rainbow" ?

/* 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 inp =new Scanner(System.in);
int t=inp.nextInt();
int n;
int a[]=new int[100];
int c;
while(t>0)
{
c=0;
n=inp.nextInt();
if(n>=7 && n<=100)
{
for(int i=0;i<n;i++)
{
a[i]=inp.nextInt();
if(a[i]<1 || a[i]>7)
{
c++;
break;
}

        }
        if(c!=0)
            System.out.println("no");
   else
   check(a,n);
        }
        else
        System.out.println("no");

    t--;
}

}
public static void check(int a[],int n)
{
int f=0;
for(int i=0;i<(n/2)+1;i++)
{
if(a[i]!=a[n-i-1])
{
f++;
break;
}
}
if(f==0)
{
for(int i=0;i<n/2;i++)
{
if(a[i+1]-a[i]!=0 && a[i+1]-a[i]!=1)
{
f++;
break;
}
}
}
if(f==0)
System.out.println(“yes”);
else
System.out.println(“no”);
}
}

/* I think I have considered all the conditions … but still I can’t get the correct ans for this question !!
can someone help me with what mistake I did here !! */

1

15

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

Your output

yes

Expected output

no

1 Like

your check method need some correction

   public static void  check(int a[],int n)
    {

   

     int f=0;
    int sum=1;
    for(int i=0;i<=(n/2)+1;i++) //upto n/2
    {
        if(a[i]!=a[n-i-1]&&a[i]==sum)
        {
            if(ar[i]!=ar[i+1])
	      sum++;
        }
        else
        {
	 	f=1;
	 	break;
	 }

   }
  

     if(f==0&&(sum==8||sum==7))
        System.out.println("yes");
       else
        System.out.println("no");
    }

but Ai is between [1,10]
Ai=8 is possible ryt??
I tried for this too!
if(a[i]<1 || a[i]>10)

but still showing error !!

Rainbow array MUST have elements ONLY in range of [1,7] . Read the question carefully.

ok, but then … when I consider that range to be a[I] to [1,7].I am getting wrong.

if(a[i]<1 || a[I]>7)
{
c++;
break;
}

?? I am confused !!..

Array will have elements from [1,10] . But if its rainbow array, it will have elements only in range [1,7]. You have to check if inputted array is rainbow or not, so obviously you must do check for "if elements are in range [1,7].

//