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!
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
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.
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
https://www.codechef.com/viewsolution/48077638
@ssjgz could you please give me a test case where this code is giving WA.
Please help me.
1
12
1 2 3 4 5 6 6 5 4 3 2 1
Codechef please remove this problem from beginner level, it can be easy or medium level.
Not sure about java but if you have implemented a condition to check if numbers in array occur in order 1,2,3… then it will show error.
Eg: if your code shows ‘no’ for 2 1 3 4 5 7 6 7 5 4 3 1 2, then answer will be considered wrong. I think the test cases are weak.
NO
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mp map<ll,ll>
#define mpc map<char,ll>
#define mps map<string,ll>
#define pb push_back
#define pll pair<ll,ll>
#define vll vector
#define vpll vector<pair<ll,ll>>
#define prq priority_queue//max
#define prqs priority_queue<ll,vector,greater>//min
#define m_p make_pair
#define ff first
#define ss second
#define b_s binary_search
#define l_b lower_bound
#define u_b upper_bound
#define l(i,s,e) for(ll i=s;i<e;i++)
#define Test ll t;cin>>t;while(t–)
#define all(v) v.begin(),v.end()
#define mem(a,x) memset(a,x,sizeof(a))
#define ln ‘\n’
#define yes cout<<“YES\n”;
#define no cout<<“NO\n”;
const ll mod =1e9+7;
const ull INF=1e9;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main(){
fast();
ll t;
cin>>t;
while(t–){
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++){
cin>>a[i];
}
ll ans=0,r=1,p=1;
for(ll i=0;i<=n/2;i++){
if((a[i]==a[n-i-1])){
}
else{
ans=1;
break;
}
}map<ll,ll>m;
if(ans==0){
for(ll i=0;i<=n/2;i++){
m[a[i]]++;
}
for(ll i=0;i<=n/2;i++){
for(ll j=i+1;j<=n/2;j++){
if(a[i]<=a[j]){
continue;
}
else {
ans=1;
break;
}
}
}
}
if(ans==0&&m.size()==7&&a[0]==1&&a[n/2]==7)
cout<<“yes”;
else
cout<<“no”;
cout<<endl;
}
}
/* 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 sc=new Scanner(System.in);
int t = sc.nextInt();
while(t–>0)
{
int n=sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
Arrays.fill(a,0);
Arrays.fill(b,0);
int x=1;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(i>0 && a[i]!=a[i-1] && x<8)
x++;
if( a[i]==x && b[i]==0 && b[n-i-1]==0)
{
b[i]=a[i];
if(a[i]!=7)
b[n-i-1]=a[i];
}
}
System.out.println(Arrays.equals(a,b)?"yes":"no");
}
}
}
I am getting WA…can anybody plz find what’s wrong in my solution and tell me which test
case am I missing …plzzz