@mohdarsalan Here is a case where your code is giving wrong.
1
6
1 2 2 1 1 1
Okay, Thanks. Now I got it.
Yes you are right thnkx
@rishup_nitdgp in your solution, i didnt understand the condition inside the for loop
for(auto i:m1) so can you please explain that, and also can you please explain what is “i.second” and how it works.
@karthik2_1 Refer to this:
Range Based loop, Auto, Pair
If you understand the concept mentioned above, then you know that I’m just iterating over the map. The data type of i is std::pair<int,int> so, i.second tells me the value of key equal to i.first.
Can someone tell me how this is a Runtime error all the test cases are correct even the ones in this editorial it runs fine but when in submit it shows runtime error CodeChef: Practical coding for everyone
Thank You So much 
it is clearing all inputs that i m giving and also the example…plss tell whatz wrong…???
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split(" ")))
curr_count=1
k=1
uniq_nums=[]
counts=[]
for j in range(1,n):
if a[j] in uniq_nums:
k=0
break
else:
if a[j]==a[j-1]:
curr_count+=1
if j==n and (curr_count in counts):
k=0
break
else:
if j==n:
curr_count=1
if curr_count in counts:
k=0
break
else:
counts.append(curr_count)
curr_count=1
uniq_nums.append(a[j-1])
if k:
print("YES")
else:
print("NO")
thank you man, i got it now, you are a true programmer
/why my code get s error on codechef ide and give the coorect result on diferent ides/ #include
#include
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int arr[n];
int has1[n+1];
int has2[n+1];
int has3[n+1];
int con1=1;
int con2=1;
for(int i=0;i<n+1;i++)
{
has1[i]=0;
has2[i]=0;
has3[i]=0;
}
for(int i=0;i<n;i++)
{
cin>>arr[i];
has2[arr[i]]++;
}
for(int i=0;i<n+1;i++)
{
if(has2[i]==0)
has3[0]=1;
else
{
has3[has2[i]]++;
}
}
for(int i=0;i<n+1;i++)
{
if(has3[i]>1)
{
con1=0;
break;
}
}
int prev=arr[0];
for(int i=0;i<n;i++)
{
if(has1[arr[i]]==-1)
{
con2==0;
break;
}
if (prev==arr[i])
{
has1[arr[i]]++;
prev=arr[i];
}
else
{
has1[prev]=-1;
has1[arr[i]]++;
prev=arr[i];
}
}
if (con1==0 || con2==0)
cout<<“NO”<<endl;
else
cout<<“YES”<<endl;
}
}Preformatted text
What is wrong with this code:
HELP
#include
#include
using namespace std;
int calc(int arr[],int x,int c=0){
for(int i = 0;i<x;i++){
for(int j=0;j<x;j++){
if(i!=j){
if(arr[i]!=0){
if(arr[i]==arr[j]){
c++;
}
} }
}
}
return c;
}
map<int,int>count(int arr[],int x){
map<int,int>m;
for(int i=0;i<x;i++){
m[arr[i]]= m[arr[i]]+1;
}
return m;
}
int main() {
int a;
cin>>a;
for(int i=0;i<a;i++){
int x;
cin>>x;
if(x%2!=0){
cout<<“NO”<<endl;
continue;
}
int arr[x];
for(int j=0;j<x;j++){
cin>>arr[j];
}
int t=0;
map<int,int>answer=count(arr,x);
for(int w=0;w<10;w++){
for(int l=0;l<10;l++){
if(answer[l]!=0){
if(l!=w){
if(answer[l]==answer[w]){
t++;
}
}
}
}
}
int brr[x];
for(int p=0;p<x;p++){
if(arr[p]==arr[p+1]){
brr[p]=0;
}
else{
brr[p]=arr[p];
}
}
int c=calc(brr,x);
int v = c+t;
if(v==0){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
// your code goes here
return 0;
}
`//why codechef ide give me error while other ides gives correct //result on this code and due to this im not able to submit this //question 
#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int arr[n];
int has1[n+1];
int has2[n+1];
int has3[n+1];
int con1=1;
int con2=1;
for(int i=0;i<n+1;i++)
{
has1[i]=0;
has2[i]=0;
has3[i]=0;
}
for(int i=0;i<n;i++)
{
cin>>arr[i];
has2[arr[i]]++;
}
for(int i=0;i<n+1;i++)
{
if(has2[i]==0)
has3[0]=1;
else
{
has3[has2[i]]++;
}
}
for(int i=0;i<n+1;i++)
{
if(has3[i]>1)
{
con1=0;
break;
}
}
int prev=arr[0];
for(int i=0;i<n;i++)
{
if(has1[arr[i]]==-1)
{
con2==0;
break;
}
if (prev==arr[i])
{
has1[arr[i]]++;
prev=arr[i];
}
else
{
has1[prev]=-1;
has1[arr[i]]++;
prev=arr[i];
}
}
if (con1==0 || con2==0)
cout<<“NO”<<endl;
else
cout<<“YES”<<endl;
}
}
Hi, my solution passes the test case but still shows as wrong. Can you help me determine why?
https://www.codechef.com/viewsolution/33379019
Thank you.
My logic is to create two arrays.
Array-1 consists of all Ingredients once, and Array-2 consists of their occurrences of each ingredient.
Example -
Input => 1,1,1,3,3,5,5,5,5,2 ;
Array 1=>1,3,5,2 ;
Array 2=>3,2,4,1 ;
Now I would sort both arrays using qsort() and then test for repetition in ingredients and quantity each array by comparing with previous element.
If both elements equal , than return NO;
else continue till Size, than return YES.
But i still get wrong answer. So what is going wrong here?
Please help.
why it is showing WA.
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int a[n],freq[1001],times[n+1];
bool vis[1001];
for(int i=0;i<1001;i++) {
freq[i]=0;
vis[i]=false;
}
for(int i=0;i<n+1;i++) {
times[i]=0;
}
for(int i=0;i<n;i++){
cin>>a[i];
freq[a[i]]++;
}
for(int j=1;j<=1000;j++){
times[freq[j]]++;
}
bool flag=true;
for(int i=1;i<=n;i++){
if(times[i]>1)
flag=false;
}
bool fla=true;
vis[a[0]]=true;
for(int i=1;i<n;i++)
{
if(a[i]==a[i-1])
continue;
if(vis[a[i]]==true){
fla=false;
}
vis[a[i]]=true;
}
if(fla==true && flag==true)
cout<<"Yes";
else
cout<<"No";
cout<<"\n";
}
return 0;
}
I am a beginner here. Can anyone please guide me , why my code is failing in submission.
It is working correctly with sample case. I am attaching the solution link below.
https://www.codechef.com/viewsolution/33396431
@prince051 Here a case on which your code is failing.
1
5
1 1 1 1 1
But there are mistakes also…you can read the editorial and write the fresh code again.
@sudhir_2116 Output is case sensitive. You are printing “Yes” and “No” instead of “YES” and “NO” respectively.
@cthombare_1011 can you share the submission link?