I want to know what’s wrong in my code. I implemented as finding a subarray of length uniqueCount, where the uniqueCount is number of unique elements.
https://www.codechef.com/viewsolution/33313411
@rishup_nitdgp I have tested many cases but it is still giving WA, please tell me failing test case
https://www.codechef.com/viewsolution/33337723
Here a test case for which your code is giving wrong answer.
1
4
1 2 2 1
I think, you misunderstood the problem.
I think this is correct output because occurrences should also be distinct.
Correct me if I am wrong.
You are print Yes and No instead of YES and NO respectively.
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.