CHEFRECP - Editorial

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

I don’t understand why this approach isn’t working.

why i am getting wrong answer???
somebody please help

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t{};
cin>>t;
while(t–)
{

ll n{},i{},j{},x{},y{},c{1};
cin>>n;
vi v3;
vi v1(n+2,0);
vi v2(n+2,0);
for(i=1;i<=n;++i)
cin>>v1.at(i);
for(i=1;i<=n;++i){
for(j=0;j<n+2;++j)
{
if(v1.at(i)==v1.at(j))
v2.at(i)++;
}
}

for(i=1;i<=n;++i){
for(j=0;j<n+2;++j)
{
if(v1.at(i)==v1.at(j))
{
if(v1.at(j-1)!=v1.at(i)&&v1.at(j+1)!=v1.at(i)&&v2.at(i)!=1)
{
x=1;
break;
}}
}
}

for(i=1;i<=n;++i)
{ 
    if(v1.at(i)==v1.at(i+1))
    c++;
    else
    { 
        v3.push_back(c);
        c=1;
    }
}

/for(i=0;i<v3.size();++i)
cout<<v3.at(i)<<" ";
cout<<endl;
/
sort(v3.begin(),v3.end());
for(i=0;i<v3.size()-1;++i)
{
if(v3.at(i)==v3.at(i+1))
{
y=1;
break;
}
}
//cout<<x<<" "<<y<<endl;
if(x+y==0)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
}

You are not supposed to sort the inputs, that’s where you are wrong

please tell my mistake

Why am I getting a WA? Can you give me a test case for which this fails?
https://www.codechef.com/viewsolution/33301484

https://www.codechef.com/viewsolution/33316760
I was getting WA, I want to know where I went wrong I mean on which test case condition.

“arri” stores the ingredient sequence.

“temp” is used to check if current element is already visited or not

“dic” is counting occurrence of each element…

“dic2” is storing count of each element from dic.

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

Anyone please let me know where this solution fails… you can provide me testcase or point out my mistake.

for(int i=1;i<1001;i++)
{
hash[i]=0;
}
*for this you can simply use * hash[1001] = { } ;
It will automatically initialise your array to 0.

**** For you second logic just sort the hash array and check if hash[i]==hash[i+1];
This will check for distinct element…

your soln is failing simple testcases.
1
1 1 7 8 9

output must be NO bc frequency of 7 8 9 are 1

from collections import Counter
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
s=set()
counter=0
for i in range(n):
if a[i] not in s:
s.add(a[i])

    else:
        if a[i]==a[i-1]:
            counter=0
        else:
            print("NO")
            counter=1
            break
if counter==0:
    l=list(Counter(a).values())
    l.sort()
    m=0
    for i in range(len(l)):
        if l[i]==m:
            print("NO")
            counter=1
            break
        else:
            m=l[i]
            counter=0
    if counter==0:
        print("YES")

1
5
1 1 7 8 9
ouput:NO

can someone give me the test casesusedfor checking??

please help
https://www.codechef.com/viewsolution/33302473
it passes all inputs that i give

I am getting correct in testcase. Can you provide some test cases

I just check it with its sorted list, about the occurrence of same ingredient

Since I am new to coding Please tell why I got WA.Anyone so that I can improve
Here is my solution
https://www.codechef.com/viewsolution/33312715

`int m1[10];``
m1[a[i]]++; plzz explain anyone what does this line exactly do just explain how m1 array effects m1[a[i]];

I have a doubt here if I use A : {1,1, 4, 2, 2, 2} freq : {0, 2, 3, 0, 1, 0} and times : {3, 1, 1, 1, 0, 0}
then on check it times[i] > 1 flag will be false then answer will get “NO” but it should be “YES”. Please tell me where I am wrong?

bro can u explain what does this do
int m[10];
int a[10];
m[a[i]]++;
what does m[a[i]]++ do and how it works

#include
#include<bits/stdc++.h>
using namespace std;
int main()
{
cout<<“enter test cases”<<endl;
int t;
int repeat=0;
cin>>t;

int n;
int i;
int a[10];
while(t>0)
{
cout<<“enter size of array”<<endl;
cin>>n;
cout<<“enter elements of array”<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i]==a[j])
{
repeat++;
}
}
}
if(repeat%2==0)
{
cout<<“yes”<<endl;
}
else
{
cout<<“no”<<endl;
}
t–;
}
}

may be it is

for i in range(n):

m[a[i]] += 1